Skip to content

Commit cad7cc2

Browse files
committed
js
1 parent d18f501 commit cad7cc2

File tree

2 files changed

+25
-2
lines changed
  • clients/algoliasearch-client-javascript/packages/client-common/src/transporter
  • tests/CTS/client/ingestion

2 files changed

+25
-2
lines changed

clients/algoliasearch-client-javascript/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
}

tests/CTS/client/ingestion/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"csharp": "<html><body>429 too many requests</body></html>",
2828
"go": "API error [429] Too Many Requests",
2929
"java": "Status Code: 429 - Too Many Requests",
30-
"javascript": "<html><body>429 Too Many Requests</body></html>",
30+
"javascript": "Too Many Requests",
3131
"kotlin": "Client request(GET http://%localhost%:6676/1/html-error) invalid: 429 Too Many Requests. Text: \\\"<html><body>429 Too Many Requests</body></html>\\\"",
3232
"php": "429: Too Many Requests",
3333
"python": "Too Many Requests",

0 commit comments

Comments
 (0)