Skip to content

Commit

Permalink
fix(cts): add tests for HTML error (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#4097

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Pierre Millot <[email protected]>
  • Loading branch information
algolia-bot and millotp committed Nov 19, 2024
1 parent a511e51 commit 49fc82b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/client-common/src/transporter/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ export function deserializeSuccess<TObject>(response: Response): TObject {
}
}

const httpMessages: Record<number, string> = {
400: 'Bad Request',
401: 'Unauthorized',
402: 'Payment Required',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
407: 'Proxy Authentication Required',
408: 'Request Timeout',
409: 'Conflict',
410: 'Gone',
411: 'Length Required',
412: 'Precondition Required',
413: 'Request Entry Too Large',
414: 'Request-URI Too Long',
415: 'Unsupported Media Type',
416: 'Requested Range Not Satisfiable',
417: 'Expectation Failed',
418: "I'm a teapot",
429: 'Too Many Requests',
};

export function deserializeFailure({ content, status }: Response, stackFrame: StackFrame[]): Error {
try {
const parsed = JSON.parse(content);
Expand All @@ -92,5 +115,5 @@ export function deserializeFailure({ content, status }: Response, stackFrame: St
} catch {
// ..
}
return new ApiError(content, status, stackFrame);
return new ApiError(status in httpMessages ? httpMessages[status] : content, status, stackFrame);
}

0 comments on commit 49fc82b

Please sign in to comment.