ignite
ignite copied to clipboard
How we can interceptor Apisauce for catching error instead of doing it in every request ?
What's going on? I want to you reference API interceptor of Axios to catch error from Server. But I don't know how to do?
Steps to reproduce
- I see this guild https://github.com/axios/axios#interceptors
- I tried using it on setup Api but It be not working. I was stuck every request. It was look like ascending loop. Please help me!
private api: Api constructor(api: Api) { this.api = api api.apisauce.axiosInstance.interceptors.request.use((c) => { console.log(' sta ',c) return c }) }
ignite doctor results:
You can use ignites general api problem file "api-problem.ts"'s function in api.ts in setup() functions. If you want to show alert ot toast you can edit api-problem.ts file as per your requirement.
this.apisauce.addAsyncResponseTransform(response => async () => {
if (!response.ok) {
const problem = getGeneralApiProblem(response)
}
})
Depending on server setup the server could send a 500 when you have a "Internal Server Error" then you can handle it in the interceptor:
this.apisauce.addMonitor(monitor => {
if (monitor.status === 500) {
__DEV__ && console.tron.log('Server error!')
}
})
DEV && console.tron.log('Server error!')
it is not working
There has been a lot of changes since this issue last had activity. This is going to be closed for now, but please re-open if this still needs attention.