Spaces:
Sleeping
Sleeping
Download server/src/proxy/common/error.rs from doasyousay/gemini: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/doasyousay/gemini/resolve/main/server/src/proxy/common/error.rs
- Command line
-
hf download hf://spaces/doasyousay/gemini/server/src/proxy/common/error.rs
-
curl -L -o error.rs https://huggingface.co/spaces/doasyousay/gemini/resolve/main/server/src/proxy/common/error.rs
1.11 kB
| // 错误处理 | |
| use thiserror::Error; | |
| use axum::{http::StatusCode, Json, response::IntoResponse}; | |
| pub enum ProxyError { | |
| UpstreamError(String), | |
| TransformError(String), | |
| AccountError(String), | |
| RateLimitExceeded, | |
| InvalidRequest(String), | |
| } | |
| impl IntoResponse for ProxyError { | |
| fn into_response(self) -> axum::response::Response { | |
| let status = match &self { | |
| ProxyError::InvalidRequest(_) => StatusCode::BAD_REQUEST, | |
| ProxyError::RateLimitExceeded => StatusCode::TOO_MANY_REQUESTS, | |
| ProxyError::AccountError(_) => StatusCode::UNAUTHORIZED, | |
| _ => StatusCode::INTERNAL_SERVER_ERROR, | |
| }; | |
| let body = serde_json::json!({ | |
| "error": { | |
| "message": self.to_string(), | |
| "type": format!("{:?}", self) | |
| } | |
| }); | |
| (status, Json(body)).into_response() | |
| } | |
| } | |