fix:extra error handling for gemini (#1268)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use reqwest::StatusCode;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
@@ -35,3 +36,41 @@ impl From<reqwest::Error> for ProviderError {
|
||||
ProviderError::ExecutionError(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum GoogleErrorCode {
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
Forbidden = 403,
|
||||
NotFound = 404,
|
||||
TooManyRequests = 429,
|
||||
InternalServerError = 500,
|
||||
ServiceUnavailable = 503,
|
||||
}
|
||||
|
||||
impl GoogleErrorCode {
|
||||
pub fn to_status_code(&self) -> StatusCode {
|
||||
match self {
|
||||
Self::BadRequest => StatusCode::BAD_REQUEST,
|
||||
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
||||
Self::Forbidden => StatusCode::FORBIDDEN,
|
||||
Self::NotFound => StatusCode::NOT_FOUND,
|
||||
Self::TooManyRequests => StatusCode::TOO_MANY_REQUESTS,
|
||||
Self::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::ServiceUnavailable => StatusCode::SERVICE_UNAVAILABLE,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_code(code: u64) -> Option<Self> {
|
||||
match code {
|
||||
400 => Some(Self::BadRequest),
|
||||
401 => Some(Self::Unauthorized),
|
||||
403 => Some(Self::Forbidden),
|
||||
404 => Some(Self::NotFound),
|
||||
429 => Some(Self::TooManyRequests),
|
||||
500 => Some(Self::InternalServerError),
|
||||
503 => Some(Self::ServiceUnavailable),
|
||||
_ => Some(Self::InternalServerError),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user