@ghii/http-loader
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -28,9 +28,14 @@ "use strict"; | ||
})); | ||
it('attempt to make a call that fails silently', () => __awaiter(void 0, void 0, void 0, function* () { | ||
mockedAxios.get.mockRejectedValue({ response: { status: 404 }, message: 'test' }); | ||
yield http_loader_1.default('http://localhost:3000/.wellknown')(); | ||
})); | ||
it('attempt to make a call that fails', () => __awaiter(void 0, void 0, void 0, function* () { | ||
mockedAxios.get.mockRejectedValue(new Error()); | ||
mockedAxios.get.mockRejectedValue({ response: { status: 404 }, message: 'test' }); | ||
try { | ||
const test = yield http_loader_1.default('http://localhost:3000/.wellknown')(); | ||
yield http_loader_1.default('http://localhost:3000/.wellknown', { throwOnError: true })(); | ||
} | ||
catch (err) { | ||
expect(err).toBeDefined(); | ||
expect(err.message).toContain('test'); | ||
} | ||
@@ -37,0 +42,0 @@ })); |
@@ -16,3 +16,3 @@ "use strict"; | ||
const axios_1 = __importDefault(require("axios")); | ||
function httpLoader(urlEndpoint, headers) { | ||
function httpLoader(urlEndpoint, { headers, throwOnError = false, logger = (err, message) => console.log(message, err), } = {}) { | ||
return function () { | ||
@@ -25,3 +25,7 @@ return __awaiter(this, void 0, void 0, function* () { | ||
catch (err) { | ||
throw new Error(`Call in error: ${err.message}`); | ||
const msg = `${err.response.status} GET ${urlEndpoint} : ${err.message}`; | ||
logger(err, msg); | ||
if (throwOnError) | ||
throw new Error(msg); | ||
return {}; | ||
} | ||
@@ -28,0 +32,0 @@ }); |
import { Loader } from '@ghii/ghii'; | ||
export default function httpLoader(urlEndpoint: string, headers?: any): Loader; | ||
export default function httpLoader(urlEndpoint: string, { headers, throwOnError, logger, }?: { | ||
headers?: any; | ||
throwOnError?: boolean; | ||
logger?: (err: any, message: string) => void; | ||
}): Loader; | ||
//# sourceMappingURL=http-loader.d.ts.map |
{ | ||
"name": "@ghii/http-loader", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A Funny http loader for ghii configuration manager ", | ||
@@ -5,0 +5,0 @@ "maintainers": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
11083
88