errorHandle function

Map<String, dynamic> errorHandle({
  1. DioError? error,
  2. bool base = false,
})

Implementation

Map<String, dynamic> errorHandle({DioError? error, bool base = false}) {
  var message = 'unknown_error';

  Map<String, dynamic>? data;

  switch (error?.type) {
    case DioErrorType.sendTimeout:
    case DioErrorType.receiveTimeout:
      message = 'request_time_out';
      break;
    case DioErrorType.response:
      if (error?.response?.data is Map<String, dynamic>) {
        data = error?.response?.data as Map<String, dynamic>;
        message = data['message'] as String;
      }
      break;
    default:
      message = 'Server đang bảo trì vui lòng thử lại sau';
      break;
  }

  ///Logout
  if (rejectCode.contains(message)) {}

  return <String, dynamic>{
    'success': false,
    'message': message,
    'data': data,
  };
}