HTTP-Statuscode on useFetch()

hi, I wanted to use "useFetch" to query data from an API. How do I get the HTTP status code from the response?
5 Replies
Moritz Walter
Moritz WalterOP9mo ago
I almost thought so I don't know if it's me, but when I make myself a routeRules
routeRules: {
'/api/**': { proxy: {to: 'https://api.domain.de/api/**'} }
},
routeRules: {
'/api/**': { proxy: {to: 'https://api.domain.de/api/**'} }
},
then i get "ECONNREFUSED" in the server-console browser console works without problems make the requests with axois, for the statuscode
manniL
manniL9mo ago
I'd use $fetch.raw + useAsyncData 🙂
Moritz Walter
Moritz WalterOP9mo ago
const apiRequest: any = await $fetch("/api" + url, {
method: httpMethod,
headers: {
...headers,
'Content-Type': 'application/json',
},
body: httpMethod != 'GET' ? JSON.stringify(request) : undefined,
params: httpMethod == 'GET' ? request : {},
});
const apiRequest: any = await $fetch("/api" + url, {
method: httpMethod,
headers: {
...headers,
'Content-Type': 'application/json',
},
body: httpMethod != 'GET' ? JSON.stringify(request) : undefined,
params: httpMethod == 'GET' ? request : {},
});
i have made a function that calls this up, how do i do it there?
manniL
manniL9mo ago
$fetch.raw(
Moritz Walter
Moritz WalterOP9mo ago
works so far, thank you. How do I call up the status code for a 4xx? it throws an exception. nvm "ignoreResponseError"
Want results from more Discord servers?
Add your server