@@ -14,37 +14,34 @@ export class ApiClientError extends Error {
14
14
response : Response ,
15
15
message : string = `error calling Atlas API`
16
16
) : Promise < ApiClientError > {
17
- const { text , body } = await this . extractErrorMessage ( response ) ;
17
+ const { errorMessage , body } = await this . extractErrorMessage ( response ) ;
18
18
19
- const errorMessage =
20
- text . length > 0
21
- ? `${ message } : [${ response . status } ${ response . statusText } ] ${ text . trim ( ) } `
22
- : `${ message } : ${ response . status } ${ response . statusText } ` ;
23
-
24
- return new ApiClientError ( errorMessage , response , body ) ;
19
+ return new ApiClientError ( `${ message } : ${ errorMessage } ` , response , body ) ;
25
20
}
26
21
27
22
private static async extractErrorMessage (
28
23
response : Response
29
- ) : Promise < { text : string ; body : ApiError | undefined } > {
30
- let text : string = "" ;
24
+ ) : Promise < { errorMessage : string ; body : ApiError | undefined } > {
25
+ let errorMessage : string = "" ;
31
26
let body : ApiError | undefined = undefined ;
32
27
try {
33
28
body = ( await response . json ( ) ) as ApiError ;
34
- text = body . reason || "unknown error" ;
29
+ errorMessage = body . reason || "unknown error" ;
35
30
if ( body . detail && body . detail . length > 0 ) {
36
- text = `${ text } ; ${ body . detail } ` ;
31
+ errorMessage = `${ errorMessage } ; ${ body . detail } ` ;
37
32
}
38
33
} catch {
39
34
try {
40
- text = await response . text ( ) ;
35
+ errorMessage = await response . text ( ) ;
41
36
} catch {
42
- text = "" ;
37
+ errorMessage = "unknown error " ;
43
38
}
44
39
}
45
40
41
+ errorMessage = `[${ response . status } ${ response . statusText } ] ${ errorMessage . trim ( ) } ` ;
42
+
46
43
return {
47
- text ,
44
+ errorMessage ,
48
45
body,
49
46
} ;
50
47
}
0 commit comments