fetch wrapper for api calls
Hello people,
I have struggling with creating a nice wrapper around $fetch from a long time now. Here is a complete overview of what I want. A function that I can use for authenticated requests and when a request gives unauthorized error (401) means the current auth token is expired then I want to call refresh token api and update the auth token, retry the previous request with new token.
Here is what I have been able to come up with:
Please review this and provide your valuable advice.
Another thing that I have struggled with a lot is use of
useAsyncData
or useFetch
for requests that don’t involve reactive values. These requests can be signup, login or requests that are needed to be sent on some user action. How should I use my fetch wrapper should I use it with useAsyncData
for a much nicer error handling or use try catch
Thank you very much0 Replies