pub enum HttpError {
Show 15 variants
BadRequest(String),
Unauthorized(String),
Forbidden(String),
NotFound(String),
MethodNotAllowed(String),
RequestTimeout(String),
Conflict(String),
PayloadTooLarge(String),
UriTooLong(String),
UnsupportedMediaType(String),
UnprocessableEntity(String),
TooManyRequests(String),
InternalServerError(String),
ServiceUnavailable(String),
GatewayTimeout(String),
}Expand description
HTTP 错误类型枚举
定义了 HTTP 服务中可能出现的各种错误类型, 每种错误类型对应特定的 HTTP 状态码。
Variants§
BadRequest(String)
错误请求 (400)
未授权 (401)
Forbidden(String)
禁止访问 (403)
NotFound(String)
资源未找到 (404)
MethodNotAllowed(String)
方法不允许 (405)
RequestTimeout(String)
请求超时 (408)
Conflict(String)
冲突 (409)
PayloadTooLarge(String)
请求实体过大 (413)
UriTooLong(String)
URI 过长 (414)
UnsupportedMediaType(String)
不支持的媒体类型 (415)
UnprocessableEntity(String)
请求格式错误 (422)
TooManyRequests(String)
请求过于频繁 (429)
InternalServerError(String)
内部服务器错误 (500)
服务不可用 (503)
GatewayTimeout(String)
网关超时 (504)
Implementations§
Source§impl HttpError
impl HttpError
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
获取错误对应的 HTTP 状态码
Sourcepub fn error_code(&self) -> &'static str
pub fn error_code(&self) -> &'static str
获取错误码字符串
Sourcepub fn bad_request(msg: impl Into<String>) -> Self
pub fn bad_request(msg: impl Into<String>) -> Self
创建错误请求错误
创建未授权错误
Sourcepub fn method_not_allowed(msg: impl Into<String>) -> Self
pub fn method_not_allowed(msg: impl Into<String>) -> Self
创建方法不允许错误
Sourcepub fn request_timeout(msg: impl Into<String>) -> Self
pub fn request_timeout(msg: impl Into<String>) -> Self
创建请求超时错误
Sourcepub fn payload_too_large(msg: impl Into<String>) -> Self
pub fn payload_too_large(msg: impl Into<String>) -> Self
创建请求实体过大错误
创建服务不可用错误
Sourcepub fn gateway_timeout(msg: impl Into<String>) -> Self
pub fn gateway_timeout(msg: impl Into<String>) -> Self
创建网关超时错误
Trait Implementations§
Source§impl<'de> Deserialize<'de> for HttpError
impl<'de> Deserialize<'de> for HttpError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Error for HttpError
impl Error for HttpError
1.30.0 · 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 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl IntoResponse for HttpError
impl IntoResponse for HttpError
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Create a response.
Auto Trait Implementations§
impl Freeze for HttpError
impl RefUnwindSafe for HttpError
impl Send for HttpError
impl Sync for HttpError
impl Unpin for HttpError
impl UnsafeUnpin for HttpError
impl UnwindSafe for HttpError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
Call the handler with the given request.
Source§fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
Apply a
tower::Layer to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Convert the handler into a
Service by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Convert the handler into a
Service and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
Convert the handler into a
MakeService and no state. Read moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
Convert the handler into a
MakeService which stores information
about the incoming connection and has no state. Read more