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 {
3131 this . name = "ApiClientError" ;
3232 this . response = response ;
3333 }
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+ }
3443}
3544
3645export interface ApiClientOptions {
@@ -62,18 +71,7 @@ export class ApiClient {
6271 private errorMiddleware = ( ) : Middleware => ( {
6372 async onResponse ( { response } ) {
6473 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 ) ;
7775 }
7876 } ,
7977 } ) ;
You can’t perform that action at this time.
0 commit comments