Type Alias: FetchInterceptorResponse
FetchInterceptorResponse =
Interceptor<Response,FetchArgsInterceptor>
Defined in: packages/fetch/src/types/interceptors.ts:120
Fetch response interceptor to be invoked before making a fetch request.
This interceptor can also be used as a transformer by return a different/modified Response.
Example
Intercept and transform response:
javascript
import fetch from '@superutils/fetch'
// After successful login, retrieve full user details.
// This is probably better suited as a result transformer but play along as this is
// just a hypothetical scenario ;)
const getUser = async response => {
const authResult = await response.json()
const userDetails = await fetch.get('[DUMMYJSON-DOT-COM]/users/1')
const userAuth = { ...userDetails, ...authResult }
return new Response(JSON.stringify(userAuth))
}
const user = await fetch.post(
'[DUMMYJSON-DOT-COM]/user/login',
{ // data/request body
username: 'emilys',
password: 'emilyspass',
expiresInMins: 30,
},
{ interceptors: { response: [getUser] } }
)