Spaces:
Runtime error
Runtime error
Download src/error.rs from ankeke2026/ankeke: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/ankeke2026/ankeke/resolve/main/src/error.rs
- Command line
-
hf download hf://spaces/ankeke2026/ankeke/src/error.rs
-
curl -L -o error.rs https://huggingface.co/spaces/ankeke2026/ankeke/resolve/main/src/error.rs
1.3 kB
| // SPDX-License-Identifier: AGPL-3.0-only | |
| // Copyright (C) 2025 Moew72 <Moew72@proton.me> | |
| use ntex::web; | |
| use serde::Serialize; | |
| pub(crate) enum Error { | |
| Io( std::io::Error), | |
| FromUtf8( std::string::FromUtf8Error), | |
| DataEncoding( data_encoding::DecodeError), | |
| NtexRuntimeJoinHandle( ntex::rt::JoinError), | |
| Other(String), | |
| } | |
| pub type Result<T> = std::result::Result<T, Error>; | |
| pub(crate) trait Context<T> { | |
| fn context(self, ctx: Error) -> Result<T>; | |
| } | |
| impl<T> Context<T> for Option<T> { | |
| fn context(self, ctx: Error) -> Result<T> { | |
| match self { | |
| Some(v) => Ok(v), | |
| None => Err(ctx), | |
| } | |
| } | |
| } | |
| impl web::WebResponseError for Error { | |
| fn error_response(&self, _: &ntex::web::HttpRequest) -> ntex::http::Response { | |
| struct RespBody { | |
| status: u16, | |
| message: String, | |
| } | |
| web::HttpResponse::build(self.status_code()).json(&RespBody { | |
| status: 400, | |
| message: self.to_string(), | |
| }) | |
| } | |
| } | |