Skip to content

Commit 39599e2

Browse files
fmenezesCopilot
andauthored
Update src/common/atlas/apiClientError.ts
Co-authored-by: Copilot <[email protected]>
1 parent 6bff85c commit 39599e2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/common/atlas/apiClientError.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ export class ApiClientError extends Error {
1414
response: Response,
1515
message: string = `error calling Atlas API`
1616
): Promise<ApiClientError> {
17+
const { text, body } = await this.extractErrorMessage(response);
18+
19+
const errorMessage = text.length > 0
20+
? `${message}: [${response.status} ${response.statusText}] ${text.trim()}`
21+
: `${message}: ${response.status} ${response.statusText}`;
22+
23+
return new ApiClientError(errorMessage, response, body);
24+
25+
return new ApiClientError(text, response, body);
26+
}
27+
28+
private static async extractErrorMessage(response: Response): Promise<{ text: string; body: ApiError | undefined }> {
1729
let text: string = "";
1830
let body: ApiError | undefined = undefined;
1931
try {

0 commit comments

Comments
 (0)