File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -130,14 +130,22 @@ function createConfiguration(options?: ApiOptions) {
130
130
throw new UnauthorizedError ( )
131
131
}
132
132
133
- if ( response . status < 200 || response . status >= 300 ) {
134
- const body = await response . text ( )
133
+ if ( ! response . ok ) {
134
+ let message : string | undefined
135
135
136
136
try {
137
- throw new ApiError ( JSON . parse ( body ) . message )
137
+ const contentType = response . headers . get ( 'content-type' )
138
+
139
+ if ( contentType ?. includes ( 'application/json' ) ) {
140
+ message = ( await response . json ( ) ) . message
141
+ } else if ( contentType ?. includes ( 'text/' ) ) {
142
+ message = await response . text ( )
143
+ }
138
144
} catch {
139
- throw new ApiError ( )
145
+ // ignore
140
146
}
147
+
148
+ throw new ApiError ( message )
141
149
}
142
150
143
151
; ( response as ExtendedResponse ) . config = config
You can’t perform that action at this time.
0 commit comments