Skip to content

Commit

Permalink
Merge pull request #177 from lifeomic/EOCI-117/improve-error-messages
Browse files Browse the repository at this point in the history
fix: include method and url in request error message
  • Loading branch information
epeters3 authored Aug 22, 2024
2 parents 8876494 + 5461b68 commit c0506de
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 98 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"arrowParens": "always",
"trailingComma": "all",
"singleQuote": true
}
22 changes: 18 additions & 4 deletions src/adapters/helpers/lambdaResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ const payloadToData = (config: AlphaOptions, payload: Payload) => {
if (!config.responseType) return payload.body;

switch (config.responseType) {
case 'arraybuffer': return new TextEncoder().encode(payload.body);
default: throw new Error('Unhandled responseType requested: ' + config.responseType);
case 'arraybuffer':
return new TextEncoder().encode(payload.body);
default:
throw new Error(
'Unhandled responseType requested: ' + config.responseType,
);
}
};

Expand All @@ -39,8 +43,18 @@ export const lambdaResponse = (
statusText: http.STATUS_CODES[payload.statusCode] as string,
};

if (typeof config.validateStatus === 'function' && !config.validateStatus(response.status)) {
throw new RequestError(`Request failed with status code ${response.status}`, config, request, response);
if (
typeof config.validateStatus === 'function' &&
!config.validateStatus(response.status)
) {
throw new RequestError(
`Request${config.method ? ' ' + config.method.toUpperCase() : ''} ${
config.url
} failed with status code ${response.status}`,
config,
request,
response,
);
}

return response;
Expand Down
Loading

0 comments on commit c0506de

Please sign in to comment.