Skip to content

Commit

Permalink
fix: Moving the error wrapper for the Ky Requester to be only around …
Browse files Browse the repository at this point in the history
…the Ky function request. Also checking to see if the error contains a response before looking for an error message.

fixes: #343
  • Loading branch information
jdalrymple committed Jun 10, 2019
1 parent facd537 commit a54a6ae
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/infrastructure/KyRequester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,25 @@ async function processBody(response) {
methods.forEach(m => {
KyRequester[m] = async function(service, endpoint, options) {
const requestOptions = defaultRequest(service, { ...options, method: m });
let response;

try {
const response = await Ky(endpoint, requestOptions);
const { status } = response;
const headers = responseHeadersAsObject(response);
const body = await processBody(response);

return { body, headers, status };
response = await Ky(endpoint, requestOptions);
} catch (e) {
const output = await e.response.json();

e.description = output.error || output.message;
if (e.response) {
const output = await e.response.json();

e.description = output.error || output.message;
}

throw e;
}

const { status } = response;
const headers = responseHeadersAsObject(response);
const body = await processBody(response);

return { body, headers, status };
};
});

Expand Down

0 comments on commit a54a6ae

Please sign in to comment.