I am using Dio to fetch/post some information from/to the API. What I want is that any time I call an API and it returns an error (401, 403, 404, 500, etc...), I want an alert to popup and inform the user with the error details. I added the necessary interceptor to intercept the error and get the required information to show, however I could not find a way to show the alert.
class HttpCustomClient {
static Dio configureDio() {
final dio = Dio();
dio.options.baseUrl = AppConsts.baseUrl;
dio.interceptors.add(InterceptorsWrapper(onError: ((exception, handler) {
var errorText = exception.response!.data['error'];
//Insert code here to show an alert with errorText
return handler.next(exception);
})));
return dio;
}
}