N
Nuxt2y ago
TorErik

Get error code from $fetch

How can I get the error code from $fetch when a request fails? I need to do call different methods based on the type of error. I have server route that returns a promise like this, but it only logs the error message and doesn't give any other information:
$fetch.raw(url, {
method: 'GET',
headers: { 'Authorization': 'Bearer ' + token, },
params: requestParams,
}).catch((error) => {
console.log(error)
})
$fetch.raw(url, {
method: 'GET',
headers: { 'Authorization': 'Bearer ' + token, },
params: requestParams,
}).catch((error) => {
console.log(error)
})
6 Replies
TorErik
TorErik2y ago
Anyone?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
TorErik
TorErik2y ago
Doesn't work as error object is undefined
TorErik
TorErik2y ago
GitHub
Add an option to allow http errors · Issue #207 · unjs/ofetch
ofetch by default throws an error if the response status code is any of http standard error codes (such as 50x). However there are situations that users prefer to always get it as a response. Curre...
TorErik
TorErik2y ago
Just have to wait for this update I guess
cosbgn
cosbgn2y ago
it's error.data I think
Want results from more Discord servers?
Add your server