-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clone Response before logging (#1662)
- Loading branch information
1 parent
9c53bd2
commit daa04af
Showing
3 changed files
with
7 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,11 @@ | ||
import { encodeBuffer, IsomorphicResponse } from '@mswjs/interceptors' | ||
|
||
const noop = () => { | ||
throw new Error('Not implemented') | ||
} | ||
import { IsomorphicResponse } from '@mswjs/interceptors' | ||
|
||
export function createResponseFromIsomorphicResponse( | ||
response: IsomorphicResponse, | ||
): Response { | ||
return { | ||
...response, | ||
ok: response.status >= 200 && response.status < 300, | ||
url: '', | ||
type: 'default', | ||
return new Response(response.body, { | ||
status: response.status, | ||
statusText: response.statusText, | ||
headers: response.headers, | ||
body: new ReadableStream(), | ||
redirected: response.headers.get('Location') != null, | ||
async text() { | ||
return response.body || '' | ||
}, | ||
async json() { | ||
return JSON.parse(response.body || '') | ||
}, | ||
async arrayBuffer() { | ||
return encodeBuffer(response.body || '') | ||
}, | ||
bodyUsed: false, | ||
formData: noop, | ||
blob: noop, | ||
clone: noop, | ||
} | ||
}) | ||
} |