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§
Sourcefn bad_request(self) -> HttpResult<T>
fn bad_request(self) -> HttpResult<T>
将错误转换为验证错误 (400)
将错误转换为认证错误 (401)
Sourcefn forbidden(self) -> HttpResult<T>
fn forbidden(self) -> HttpResult<T>
将错误转换为权限错误 (403)
Sourcefn not_found(self) -> HttpResult<T>
fn not_found(self) -> HttpResult<T>
将错误转换为资源未找到错误 (404)
Sourcefn internal_error(self) -> HttpResult<T>
fn internal_error(self) -> HttpResult<T>
将错误转换为内部服务器错误 (500)
Sourcefn with_http_error(self, error: HttpError) -> HttpResult<T>
fn with_http_error(self, error: HttpError) -> HttpResult<T>
使用自定义 HttpError 转换
Sourcefn map_http_error<F>(self, f: F) -> HttpResult<T>
fn map_http_error<F>(self, f: F) -> HttpResult<T>
使用错误消息转换函数
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.