Download src/errors.rs from arami21/rms-app: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/arami21/rms-app/resolve/main/src/errors.rs
- Command line
-
hf download hf://spaces/arami21/rms-app/src/errors.rs
-
curl -L -o errors.rs https://huggingface.co/spaces/arami21/rms-app/resolve/main/src/errors.rs
1.17 kB
| use actix_web::{HttpResponse, ResponseError}; | |
| use derive_more::{Display, Error}; | |
| pub enum MyError { | |
| NotFound, | |
| Supabase(String), | |
| } | |
| impl From<reqwest::Error> for MyError { | |
| fn from(err: reqwest::Error) -> Self { | |
| println!("\n================ ERROR REQWEST ================"); | |
| println!("{:#?}", err); | |
| if let Some(status) = err.status() { | |
| println!("STATUS: {}", status); | |
| } | |
| println!("================================================\n"); | |
| MyError::Supabase(err.to_string()) | |
| } | |
| } | |
| impl ResponseError for MyError { | |
| fn error_response(&self) -> HttpResponse { | |
| match self { | |
| MyError::NotFound => { | |
| HttpResponse::NotFound().json(serde_json::json!({ | |
| "error": "Data tidak ditemukan" | |
| })) | |
| } | |
| MyError::Supabase(msg) => { | |
| HttpResponse::InternalServerError().json(serde_json::json!({ | |
| "error": msg | |
| })) | |
| } | |
| } | |
| } | |
| } |