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(cts): add tests for HTML error #4097

Merged
merged 10 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
js
  • Loading branch information
millotp committed Nov 18, 2024
commit cad7cc22eff1b4507d9cd448ca7b0ef35493adf1
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);
}
2 changes: 1 addition & 1 deletion tests/CTS/client/ingestion/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"csharp": "<html><body>429 too many requests</body></html>",
"go": "API error [429] Too Many Requests",
"java": "Status Code: 429 - Too Many Requests",
"javascript": "<html><body>429 Too Many Requests</body></html>",
"javascript": "Too Many Requests",
"kotlin": "Client request(GET http://%localhost%:6676/1/html-error) invalid: 429 Too Many Requests. Text: \\\"<html><body>429 Too Many Requests</body></html>\\\"",
"php": "429: Too Many Requests",
"python": "Too Many Requests",
Expand Down
Loading