UNPKG

weather-cli-nk_sm

Version:
52 lines (51 loc) 2.19 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import APIService from './APIService.js'; import LogService from './LogService.js'; import StorageService from './StorageService.js'; function checkErrorObj(e) { return 'response' in e; } export default class ErrorHandlerService { static fetchDB(body, successMessage = 'Done!') { return __awaiter(this, void 0, void 0, function* () { try { if (body.value) { yield StorageService.post(body); LogService.success(successMessage); } else this.res = yield StorageService.get(body.key); } catch (e) { if (e instanceof Error) LogService.error(e.message); } return this.res; }); } static fetchAPI() { var _a; return __awaiter(this, void 0, void 0, function* () { try { this.res = yield APIService.getWeather(); this.res = { body: this.res, type: 'success' }; } catch (e) { if (checkErrorObj(e) && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) == 401) LogService.error('Incorrect api-key'); else if (e instanceof Error) LogService.error(e.message); this.res = { type: 'error' }; } return this.res; }); } }