You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting Uncaught (in promise) TypeError: Failed to execute 'clone' on 'Request': Request body is already used. I have tried with:
response.request.text().then((value) => {
console.log('Request body here')
console.log(value)
})
But I'm getting TypeError: Failed to execute 'clone' on 'Request': Request body is already used.
My use case is to whenever there's a response I would like to log the request body and the response body. Is it possible to do it entirely in the response or do I have to keep track of the request, and whenever I get a response I look for the request and merge them?
The text was updated successfully, but these errors were encountered:
importreturnFetchfrom'return-fetch';constfetchExtended=returnFetch({baseUrl: 'https://jsonplaceholder.typicode.com',headers: {Accept: 'application/json'},interceptors: {response: async(response,requestArgs)=>{console.log('**** read request body from response interceptor ****');console.log(awaitnewResponse(requestArgs[1]?.body).text());returnresponse;},},});fetchExtended('/posts',{method: 'POST',body: '{"hello":"world!"}'})
return-fetch is a minimalistic, simple and powerful library. It is a simple high order function to make fetch possible to use baseUrl, default headers and interceptors. It just takes 733Byte(minified + gzipped) which is slightly smaller than fetch-intercept(762Byte) but can do everything 'fetch-intercept' provide and also do more. You can easily implement your own feature using 'return-fetch'.
Hey @mlegenhausen 👋 Great library and amazing work.
I'm trying to read the
response.request.body
in theresponse
interception:I'm getting
Uncaught (in promise) TypeError: Failed to execute 'clone' on 'Request': Request body is already used
. I have tried with:But I'm getting
TypeError: Failed to execute 'clone' on 'Request': Request body is already used
.My use case is to whenever there's a response I would like to log the request body and the response body. Is it possible to do it entirely in the
response
or do I have to keep track of the request, and whenever I get a response I look for the request and merge them?The text was updated successfully, but these errors were encountered: