Skip to main content

ErrorExt

Trait ErrorExt 

Source
pub trait ErrorExt<T> {
    // Required methods
    fn bad_request(self) -> HttpResult<T>;
    fn unauthorized(self) -> HttpResult<T>;
    fn forbidden(self) -> HttpResult<T>;
    fn not_found(self) -> HttpResult<T>;
    fn internal_error(self) -> HttpResult<T>;
    fn with_http_error(self, error: HttpError) -> HttpResult<T>;
    fn map_http_error<F>(self, f: F) -> HttpResult<T>
       where F: FnOnce(String) -> HttpError;
}
Expand description

错误扩展 trait

为 Result 类型提供便捷的错误转换方法。

Required Methods§

Source

fn bad_request(self) -> HttpResult<T>

将错误转换为验证错误 (400)

Source

fn unauthorized(self) -> HttpResult<T>

将错误转换为认证错误 (401)

Source

fn forbidden(self) -> HttpResult<T>

将错误转换为权限错误 (403)

Source

fn not_found(self) -> HttpResult<T>

将错误转换为资源未找到错误 (404)

Source

fn internal_error(self) -> HttpResult<T>

将错误转换为内部服务器错误 (500)

Source

fn with_http_error(self, error: HttpError) -> HttpResult<T>

使用自定义 HttpError 转换

Source

fn map_http_error<F>(self, f: F) -> HttpResult<T>
where F: FnOnce(String) -> HttpError,

使用错误消息转换函数

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T, E: Display> ErrorExt<T> for Result<T, E>

Implementors§