From 49fc82bfc156a7cc317b630914ecdc78c5258c8b Mon Sep 17 00:00:00 2001 From: algolia-bot Date: Tue, 19 Nov 2024 10:58:22 +0000 Subject: [PATCH] fix(cts): add tests for HTML error (generated) https://github.com/algolia/api-clients-automation/pull/4097 Co-authored-by: algolia-bot Co-authored-by: Pierre Millot --- .../client-common/src/transporter/helpers.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/client-common/src/transporter/helpers.ts b/packages/client-common/src/transporter/helpers.ts index 25cd25ae6..a4f85547b 100644 --- a/packages/client-common/src/transporter/helpers.ts +++ b/packages/client-common/src/transporter/helpers.ts @@ -82,6 +82,29 @@ export function deserializeSuccess(response: Response): TObject { } } +const httpMessages: Record = { + 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); @@ -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); }