Description
Migrating from the old library, we've leaned into the exception-throwing to handle errors and generically display an issue whenever an error is thrown. Something like this is what we've used up until now, and has been very nice to use.
export const useApiErrorToast = (error: any, onError?: (error: ApiError) => void) => {
const toast = useToast();
if (error instanceof ApiError) {
onError?.();
if (error.status >= 500) {
toast.add({
title: `${error.status}`,
description: error.body.message,
color: 'red',
});
return;
}
if (error.status >= 400 && error.status < 500) {
toast.add({
title: `${error.status}`,
description: error.body.message,
color: 'orange',
});
return;
}
}
toast.add({
title: 'Something went wrong',
color: 'red',
});
};
The new fetch client does not seem to offer similar functionality, nor is there a (to me) obvious way of achieving something similar, especially since the error response is unknown.
Description
Migrating from the old library, we've leaned into the exception-throwing to handle errors and generically display an issue whenever an error is thrown. Something like this is what we've used up until now, and has been very nice to use.
The new fetch client does not seem to offer similar functionality, nor is there a (to me) obvious way of achieving something similar, especially since the error response is
unknown.