onError method
Called when an exception was occurred during the request.
Implementation
@override
void onError(DioException err, ErrorInterceptorHandler handler) {
bool isBadConnection = err.type == DioExceptionType.connectionTimeout ||
err.type == DioExceptionType.sendTimeout ||
err.type == DioExceptionType.connectionError ||
err.type == DioExceptionType.unknown ||
err.type == DioExceptionType.receiveTimeout;
final logModel = LogModel(
time: DateTime.now().toIso8601String(),
endpoint: err.requestOptions.path,
method: err.requestOptions.method,
argument: err.requestOptions.queryParameters.toString(),
error: err.message ?? err.response?.data.toString(),
errorFrom: 'SERVER',
body: err.requestOptions.data != null
? jsonEncode(err.requestOptions.data)
: 'N/A',
deviceId: deviceId,
deviceType: deviceType,
stackTrace: err.stackTrace.toString(),
);
_handleLog(logModel, isBadConnection);
super.onError(err, handler);
}