getTogetherAIError function

TogetherAIError getTogetherAIError(
  1. String errorCode,
  2. String errorMessage
)

Returns a TogetherAIError instance based on the provided errorCode and errorMessage.

The errorCode is a string representing the specific error code returned by the API, you can find more information here https://docs.together.ai/docs/error-codes The errorMessage is a human-readable description of the error.

Implementation

TogetherAIError getTogetherAIError(String errorCode, String errorMessage) {
  return switch (errorCode) {
    'invalid_api_key' => AuthenticationError(errorMessage),
    'bad_request' => BadRequest(errorMessage),
    'not_found' => NotFound(errorMessage),
    'rate_limit_exceeded' => RateLimitExceeded(errorMessage),
    'invalid_request' => InvalidRequest(errorMessage),
    'engine_overloaded' => EngineOverloaded(errorMessage),
    'timeout' => Timeout(errorMessage),
    'server_error' => ServerError(errorMessage),
    'connection_timeout' => ConnectionTimeout(errorMessage),
    _ => UnknownServerError(errorMessage),
  };
}