Hello,
thanks for developing this library, it's very useful.
I have a question, I want to throw my own custom exception in OnError interceptor. However it's not working because in the catch block the error caught is DioError not my own exception. Can I override that to throw my exception?
Example of my interceptor
if (error.type == DioErrorType.RECEIVE_TIMEOUT ||
error.type == DioErrorType.CONNECT_TIMEOUT) {
throw TimeoutException();
} else if (error.type == DioErrorType.RESPONSE) {
switch (error.response.statusCode) {
case 401:
throw UnauthorizedException();
case 403:
throw ForbiddenException();
case 404:
throw NotFoundException();
case 500:
throw InternalServerError(message: error.message);
}
} else {
return error;
}
Thank you.
I have found a solution. I can do this by extending DioError.
Hi @skybur Would you mind to share how did you solve this problem?
Cheers!
Just extends DioError on your custom exception
example:
class MyCustomException extends DioError
{
// code here
}
Thank you, @skybur I have just done the same. Thank you cheers!
Most helpful comment
I have found a solution. I can do this by extending
DioError.