Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: include method and url in request error message #177

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No functional changes here^, just Prettier.

}
};

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
Loading