File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Validates an object is of type Response without using `instanceof`.
3+ *
4+ * @remarks Check issue #509 for more context.
5+ *
6+ * @internal
7+ */
8+ export const isResponse = ( obj : unknown ) : obj is Response =>
9+ obj !== null &&
10+ obj !== undefined &&
11+ typeof obj === 'object' &&
12+ 'status' in obj &&
13+ typeof obj . status === 'number' &&
14+ 'statusText' in obj &&
15+ typeof obj . statusText === 'string' &&
16+ 'headers' in obj &&
17+ typeof obj . headers === 'object' &&
18+ 'body' in obj &&
19+ typeof obj . body !== 'undefined'
Original file line number Diff line number Diff line change 1+ import { isResponse } from '../../helpers/is-response'
12import { isJSONObject } from '../../helpers/json'
23import { parseScalewayError } from '../errors/error-parser'
34import { ScalewayError } from '../errors/scw-error'
@@ -50,7 +51,7 @@ export const responseParser =
5051 responseType : 'json' | 'text' | 'blob' ,
5152 ) =>
5253 async ( response : Response ) : Promise < T > => {
53- if ( ! ( response instanceof Response ) ) {
54+ if ( ! isResponse ( response ) ) {
5455 throw new TypeError ( 'Invalid response object' )
5556 }
5657
You can’t perform that action at this time.
0 commit comments