@@ -14,37 +14,34 @@ 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 ) ;
17+ const { errorMessage , body } = await this . extractErrorMessage ( response ) ;
1818
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 ) ;
2520 }
2621
2722 private static async extractErrorMessage (
2823 response : Response
29- ) : Promise < { text : string ; body : ApiError | undefined } > {
30- let text : string = "" ;
24+ ) : Promise < { errorMessage : string ; body : ApiError | undefined } > {
25+ let errorMessage : string = "" ;
3126 let body : ApiError | undefined = undefined ;
3227 try {
3328 body = ( await response . json ( ) ) as ApiError ;
34- text = body . reason || "unknown error" ;
29+ errorMessage = body . reason || "unknown error" ;
3530 if ( body . detail && body . detail . length > 0 ) {
36- text = `${ text } ; ${ body . detail } ` ;
31+ errorMessage = `${ errorMessage } ; ${ body . detail } ` ;
3732 }
3833 } catch {
3934 try {
40- text = await response . text ( ) ;
35+ errorMessage = await response . text ( ) ;
4136 } catch {
42- text = "" ;
37+ errorMessage = "unknown error " ;
4338 }
4439 }
4540
41+ errorMessage = `[${ response . status } ${ response . statusText } ] ${ errorMessage . trim ( ) } ` ;
42+
4643 return {
47- text ,
44+ errorMessage ,
4845 body,
4946 } ;
5047 }
0 commit comments