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?
6 Replies
netwrx
netwrx7mo ago
That's not available for ofetch which is what that composable uses
Moritz Walter
Moritz Walter7mo 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
manniL7mo ago
I'd use $fetch.raw + useAsyncData 🙂
Moritz Walter
Moritz Walter7mo 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
manniL7mo ago
$fetch.raw(
Moritz Walter
Moritz Walter7mo 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