AppException.http constructor

AppException.http(
  1. DioError error
)

Implementation

factory AppException.http(DioError error) {
  I10nBaseExceptionText i10nException = _i10nExceptionText();

  switch (error.type) {
    case DioErrorType.cancel:
      {
        return NetworkException(fixedErrCode, i10nException.cancelRequest);
      }
    case DioErrorType.connectTimeout:
      {
        return NetworkException(fixedErrCode, i10nException.connectTimeout);
      }
    case DioErrorType.sendTimeout:
      {
        return NetworkException(fixedErrCode, i10nException.writeTimeout);
      }
    case DioErrorType.receiveTimeout:
      {
        return NetworkException(fixedErrCode, i10nException.readTimeout);
      }
    case DioErrorType.response:
      {
        try {
          int? errCode = error.response!.statusCode;
          switch (errCode) {
            case 400:
              {
                return BadRequestException(errCode!, i10nException.err400);
              }
            case 401:
              {
                return UnauthorisedException(errCode!, i10nException.err401);
              }
            case 403:
              {
                return UnauthorisedException(errCode!, i10nException.err403);
              }
            case 404:
              {
                return NotFoundException(errCode!, i10nException.err404);
              }
            case 405:
              {
                return BadRequestException(errCode!, i10nException.err405);
              }
            case 500:
              {
                return ServerException(errCode!, i10nException.err500);
              }
            case 502:
              {
                return ServerException(errCode!, i10nException.err502);
              }
            case 503:
              {
                return ServerException(errCode!, i10nException.err503);
              }
            case 505:
              {
                return ServerException(errCode!, i10nException.err505);
              }
            default:
              {
                return AppException(errCode!, error.response!.statusMessage!);
              }
          }
        } on Exception catch (_) {
          return AppException(fixedErrCode, i10nException.errDef);
        }
      }
    default:
      {
        return AppException(fixedErrCode, error.error.message);
      }
  }
}