Fix cloning response
object
This commit is contained in:
parent
50dbd4ee52
commit
95c2866b01
@ -30,6 +30,7 @@ export async function walkFetch(request: Request): Promise<any> {
|
||||
|
||||
try {
|
||||
const response = await fetch(request)
|
||||
const cloned = response.clone()
|
||||
const body = response.headers.get('Content-Type') === 'application/json'
|
||||
? await response.json()
|
||||
: await response.text()
|
||||
@ -49,8 +50,7 @@ export async function walkFetch(request: Request): Promise<any> {
|
||||
return
|
||||
}
|
||||
|
||||
const res = response.clone()
|
||||
throw new HTTPError(body.message || body, res)
|
||||
throw new HTTPError(body.message || body, cloned)
|
||||
} catch (error) {
|
||||
emit('fetchError', error)
|
||||
showAjaxError(error)
|
||||
|
@ -11,6 +11,7 @@ test('the GET method', async () => {
|
||||
ok: true,
|
||||
json,
|
||||
headers: new Map([['Content-Type', 'application/json']]),
|
||||
clone: () => ({}),
|
||||
})
|
||||
|
||||
const stub = jest.fn()
|
||||
@ -35,6 +36,7 @@ test('the POST method', async () => {
|
||||
ok: true,
|
||||
json: () => Promise.resolve({}),
|
||||
headers: new Map([['Content-Type', 'application/json']]),
|
||||
clone: () => ({}),
|
||||
})
|
||||
|
||||
const meta = document.createElement('meta')
|
||||
@ -91,11 +93,13 @@ test('low level fetch', async () => {
|
||||
ok: true,
|
||||
json,
|
||||
headers: new Map([['Content-Type', 'application/json']]),
|
||||
clone: () => ({}),
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
headers: new Map(),
|
||||
text: () => Promise.resolve('text'),
|
||||
clone: () => ({}),
|
||||
})
|
||||
|
||||
const request: RequestInit = { headers: new Headers() }
|
||||
@ -134,6 +138,7 @@ test('process backend errors', async () => {
|
||||
errors: { name: ['required'] },
|
||||
})
|
||||
},
|
||||
clone: () => ({}),
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
status: 403,
|
||||
@ -141,6 +146,7 @@ test('process backend errors', async () => {
|
||||
json() {
|
||||
return Promise.resolve({ message: 'forbidden' })
|
||||
},
|
||||
clone: () => ({}),
|
||||
})
|
||||
|
||||
const result: {
|
||||
|
Loading…
Reference in New Issue
Block a user