onError method
The callback will be executed on error.
If you want to continue the error , call handler.next.
If you want to complete the response with some custom data directly,
you can resolve a Response object with handler.resolve and other
error interceptor(s) will be skipped.
If you want to complete the response with an error message directly,
you can reject a DioError object with handler.reject, and other
error interceptor(s) will be skipped.
Implementation
@override
void onError(DioError err, ErrorInterceptorHandler handler) {
String errorStr = "\n==================== RESPONSE ====================\n"
"- URL:\n${err.requestOptions.baseUrl + err.requestOptions.path}\n"
"- METHOD: ${err.requestOptions.method}\n";
errorStr +=
"- HEADER:\n${err.response?.headers.map.mapToStructureString()}\n";
if (err.response != null && err.response!.data != null) {
errorStr += "- ERROR:\n${_parseResponse(err.response!)}\n";
} else {
errorStr += "- ERROR-TYPE: ${err.type}\n";
errorStr += "- MSG: ${err.message}\n";
}
printWrapped(errorStr);
handler.next(err);
}