onError method
Called when an exception was occurred during the request.
Implementation
@override
void onError(DioError err, ErrorInterceptorHandler handler) {
if (error) {
if (err.type == DioErrorType.badResponse) {
final uri = err.response?.requestOptions.uri;
_printBoxed(
header:
'DioError ║ Status: ${err.response?.statusCode} ${err.response?.statusMessage}',
text: uri.toString(),
);
if (err.response != null && err.response?.data != null) {
if (responseHeader) {
final responseHeaders = <String, String>{};
err.response!.headers
.forEach((k, list) => responseHeaders[k] = list.toString());
_printMapAsTable(responseHeaders, header: 'Response Headers');
}
debugPrint('╔ ${err.type.toString()}');
_printResponse(err.response!);
_printLine('╚');
}
// _printLine('╚');
debugPrint('');
} else {
_printBoxed(header: 'DioError ║ ${err.type}', text: err.message);
}
}
super.onError(err, handler);
}