UNPKG

error-flux

Version:

Network request interceptor and logger for web applications

75 lines 4.05 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 { ErrorTypes } from "./../types"; import { getConsoleErrors, getNetworkLogs, getUnhandledErrors, } from "../db/index"; import store from "../state/store"; import { StorageTypes } from "../types"; import downloadJSON from "./download-json"; export const downloadNetworkLogs = () => __awaiter(void 0, void 0, void 0, function* () { const getLogs = () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b; const { storeName: storeNameObj, dbName, storageType } = store.getState(); const storeName = storeNameObj.networkLogs; switch (storageType) { case StorageTypes.IndexedDB: return yield getNetworkLogs(); case StorageTypes.LocalStorage: return (((_a = JSON.parse(localStorage.getItem(dbName) || "{}")) === null || _a === void 0 ? void 0 : _a[storeName]) || []); case StorageTypes.SessionStorage: return (((_b = JSON.parse(sessionStorage.getItem(dbName) || "{}")) === null || _b === void 0 ? void 0 : _b[storeName]) || []); } }); try { const logs = yield getLogs(); downloadJSON({ type: ErrorTypes.Network, logs }, `${ErrorTypes.Network}_${new Date().getTime()}`); } catch (err) { } }); export const downloadConsoleErrors = () => __awaiter(void 0, void 0, void 0, function* () { const getLogs = () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b; const { storeName: storeNameObj, dbName, storageType } = store.getState(); const storeName = storeNameObj.consoleErrors; switch (storageType) { case StorageTypes.IndexedDB: return yield getConsoleErrors(); case StorageTypes.LocalStorage: return (((_a = JSON.parse(localStorage.getItem(dbName) || "{}")) === null || _a === void 0 ? void 0 : _a[storeName]) || []); case StorageTypes.SessionStorage: return (((_b = JSON.parse(sessionStorage.getItem(dbName) || "{}")) === null || _b === void 0 ? void 0 : _b[storeName]) || []); } }); try { const logs = yield getLogs(); downloadJSON({ type: ErrorTypes.Errors, logs }, `${ErrorTypes.Errors}_${new Date().getTime()}`); } catch (err) { } }); export const downloadUnhandledErrors = () => __awaiter(void 0, void 0, void 0, function* () { const getLogs = () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b; const { storeName: storeNameObj, dbName, storageType } = store.getState(); const storeName = storeNameObj.unhandledErrors; switch (storageType) { case StorageTypes.IndexedDB: return yield getUnhandledErrors(); case StorageTypes.LocalStorage: return (((_a = JSON.parse(localStorage.getItem(dbName) || "{}")) === null || _a === void 0 ? void 0 : _a[storeName]) || []); case StorageTypes.SessionStorage: return (((_b = JSON.parse(sessionStorage.getItem(dbName) || "{}")) === null || _b === void 0 ? void 0 : _b[storeName]) || []); } }); try { const logs = yield getLogs(); downloadJSON({ type: ErrorTypes.UnhandledRejections, logs }, `${ErrorTypes.UnhandledRejections}_${new Date().getTime()}`); } catch (err) { } }); //# sourceMappingURL=export.js.map