pub enum AppError {
Remote(Error),
BadRequest(String),
NotFound,
Internal(String),
Config(String),
}Expand description
应用程序错误类型
枚举了所有可能的错误情况,并为每种错误提供了清晰的描述。
实现了IntoResponse,可以直接作为Axum的响应返回。
Variants§
Remote(Error)
远程API请求错误
包含底层reqwest::Error的详细信息
BadRequest(String)
无效的输入参数
当请求参数不符合要求时返回
NotFound
请求的资源不存在
当请求的资源(歌曲、专辑、新闻等)不存在时返回
Internal(String)
服务器内部错误
当发生未预期的内部错误时返回
Config(String)
配置错误
当环境变量或配置文件格式不正确时返回
Trait Implementations§
Source§impl Error for AppError
impl Error for AppError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl IntoResponse for AppError
impl IntoResponse for AppError
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
将错误转换为HTTP响应
根据不同的错误类型返回相应的HTTP状态码和错误信息:
- 请求超时 -> 408 Request Timeout
- 远程服务错误 -> 502 Bad Gateway
- 参数错误 -> 400 Bad Request
- 资源未找到 -> 404 Not Found
- 内部错误 -> 500 Internal Server Error
- 配置错误 -> 500 Internal Server Error
Auto Trait Implementations§
impl Freeze for AppError
impl !RefUnwindSafe for AppError
impl Send for AppError
impl Sync for AppError
impl Unpin for AppError
impl !UnwindSafe for AppError
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.