ofetch
ofetch copied to clipboard
How to handle errors body
Hey ! I wanted to get the error response body in json, but the response.json() method give me the following error :
error: Body already used
I'm using onResponseError to display a log on error
const response = await ofetch(documentUrl, {
method: "POST",
body: body,
async onResponseError({ request, response, options }) {
// Log error
console.log(
"[fetch response error]",
request,
response.status,
response.body,
response.json() // Error here
)
},
})
Ah, I think it might be in response._data.
You can retrieve the parsed data using response._data.