File tree Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,15 @@ export class ApiClientError extends Error {
31
31
this . name = "ApiClientError" ;
32
32
this . response = response ;
33
33
}
34
+
35
+ static async fromResponse ( response : Response ) : Promise < ApiClientError > {
36
+ try {
37
+ const text = await response . text ( ) ;
38
+ return new ApiClientError ( `Error calling Atlas API: [${ response . status } ${ response . statusText } ] ${ text } ` , response ) ;
39
+ } catch {
40
+ return new ApiClientError ( `Error calling Atlas API: ${ response . status } ${ response . statusText } ` , response ) ;
41
+ }
42
+ }
34
43
}
35
44
36
45
export interface ApiClientOptions {
@@ -62,18 +71,7 @@ export class ApiClient {
62
71
private errorMiddleware = ( ) : Middleware => ( {
63
72
async onResponse ( { response } ) {
64
73
if ( ! response . ok ) {
65
- try {
66
- const text = await response . text ( ) ;
67
- throw new ApiClientError (
68
- `Error calling Atlas API: [${ response . status } ${ response . statusText } ] ${ text } ` ,
69
- response
70
- ) ;
71
- } catch {
72
- throw new ApiClientError (
73
- `Error calling Atlas API: ${ response . status } ${ response . statusText } ` ,
74
- response
75
- ) ;
76
- }
74
+ throw await ApiClientError . fromResponse ( response ) ;
77
75
}
78
76
} ,
79
77
} ) ;
You can’t perform that action at this time.
0 commit comments