Skip to content

Commit 49fc82b

Browse files
algolia-botmillotp
andcommitted
fix(cts): add tests for HTML error (generated)
algolia/api-clients-automation#4097 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent a511e51 commit 49fc82b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/client-common/src/transporter/helpers.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ export function deserializeSuccess<TObject>(response: Response): TObject {
8282
}
8383
}
8484

85+
const httpMessages: Record<number, string> = {
86+
400: 'Bad Request',
87+
401: 'Unauthorized',
88+
402: 'Payment Required',
89+
403: 'Forbidden',
90+
404: 'Not Found',
91+
405: 'Method Not Allowed',
92+
406: 'Not Acceptable',
93+
407: 'Proxy Authentication Required',
94+
408: 'Request Timeout',
95+
409: 'Conflict',
96+
410: 'Gone',
97+
411: 'Length Required',
98+
412: 'Precondition Required',
99+
413: 'Request Entry Too Large',
100+
414: 'Request-URI Too Long',
101+
415: 'Unsupported Media Type',
102+
416: 'Requested Range Not Satisfiable',
103+
417: 'Expectation Failed',
104+
418: "I'm a teapot",
105+
429: 'Too Many Requests',
106+
};
107+
85108
export function deserializeFailure({ content, status }: Response, stackFrame: StackFrame[]): Error {
86109
try {
87110
const parsed = JSON.parse(content);
@@ -92,5 +115,5 @@ export function deserializeFailure({ content, status }: Response, stackFrame: St
92115
} catch {
93116
// ..
94117
}
95-
return new ApiError(content, status, stackFrame);
118+
return new ApiError(status in httpMessages ? httpMessages[status] : content, status, stackFrame);
96119
}

0 commit comments

Comments
 (0)