AimuxException.fromCode constructor

AimuxException.fromCode(
  1. int code,
  2. String message, {
  3. int status = -1,
  4. int retryMs = -1,
  5. String? errorValue,
})

Dispatch code → concrete subclass (defaults for status when -1).

Implementation

factory AimuxException.fromCode(
  int code,
  String message, {
  int status = -1,
  int retryMs = -1,
  String? errorValue,
}) {
  switch (code) {
    case AimuxErrorCode.jsonParse:
      return JSONParseError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.invalidResponseData:
      return InvalidResponseDataError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.tool:
      return ToolError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.invalidArgument:
      return InvalidArgumentError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.invalidPrompt:
      return InvalidPromptError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.tokenExpired:
      return TokenExpiredError(
        message,
        status: status == -1 ? 401 : status,
        retryMs: retryMs,
        errorValue: errorValue,
      );
    case AimuxErrorCode.unsupportedFunctionality:
      return UnsupportedFunctionalityError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.noSuchModel:
      return NoSuchModelError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.noSuchProvider:
      return NoSuchProviderError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.apiCall:
      return APICallError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.timeout:
      return AimuxTimeoutError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.aborted:
      return RequestAbortedError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.other:
      return OtherError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    case AimuxErrorCode.unknown:
      return UnknownError(message, status: status, retryMs: retryMs, errorValue: errorValue);
    default:
      return AimuxException(
        message,
        code: code,
        status: status,
        retryMs: retryMs,
        errorValue: errorValue,
      );
  }
}