-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@hey-api/client-fetch does not really throw
where it should
#680
Comments
throw
properlythrow
where it should
Yeah I think this is more TanStack Query integration question as it will need a slightly different implementation to make this work 👀 |
Ok, i'll stick to using fetch then until |
the returning of an object of client.interceptors.response.use(async (response, request) => {
const statusCategory = response?.status.toString()[0]
switch (statusCategory) {
case '4': {
throw new MyApiError()
}
case '5':
throw new MyApiError()
}
return response
}) |
@frdwhite24 Thanks a lot - your solution works for me const setOpenAPIClient = () => {
const client = createClient({
baseUrl: import.meta.env["VITE_APP_API_URL"],
headers: {
Authorization: `Bearer ${idToken}`,
},
});
client.interceptors.response.use(async (response, _) => {
const statusCategory = response?.status?.toString()[0];
if (!statusCategory) {
throw new Error("Invalid response status");
}
const responseData = await response.clone().json();
const message = responseData?.detail;
if (["3", "4", "5"].includes(statusCategory)) {
const serverError = new ServerApiError(message);
console.error(message, statusCategory);
throw serverError;
}
return response;
});
}; |
Description
Using
@hey-api/client-fetch
does not actually show errors where they should be, see the comparison examples belowMy client (would love an axios client :) )
@hey-api/client-fetch ❌
Axios client ✅
OpenAPI specification (optional)
Configuration
System information (optional)
No response
The text was updated successfully, but these errors were encountered: