onError method

  1. @override
void onError(
  1. DioException err,
  2. ErrorInterceptorHandler handler
)
override

Called when an exception was occurred during the request.

Implementation

@override
void onError(DioException err, ErrorInterceptorHandler handler) {
  if (showLogError) {
    String loggerText = "ERROR API-RESPONSE";
    loggerText += "\nAPI PATH: ${err.requestOptions.baseUrl}${err.requestOptions.path}";
    loggerText += "\nMETHOD: ${err.requestOptions.method}";
    loggerText += "\nREQUEST";
    loggerText += "\nHEADER: ${err.requestOptions.headers}";
    if (err.requestOptions.data != null) {
      loggerText += "\nREQUEST DATA: ${err.requestOptions.data}";
    }
    loggerText += "\nERROR";
    loggerText += "\nHTTP STATUS CODE: ${err.response?.statusCode}";
    loggerText += "\nRESPONSE DATA: ${err.response?.data}";
    loggerText += "\nEXPLANATION: ${err.error}";
    logger.e(loggerText);
  }
  super.onError(err, handler);
}