1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-27 07:19:04 +02:00

move blocking error to web (#2660)

This commit is contained in:
Rob Ede
2022-02-22 08:45:28 +00:00
committed by GitHub
parent 1c1d6477ef
commit ad38973767
11 changed files with 52 additions and 46 deletions

View File

@ -1,6 +1,7 @@
# Changes
## Unreleased - 2021-xx-xx
### Changed
- Rename `test::{simple_service => status_service}`. [#2659]
[#2659]: https://github.com/actix/actix-web/pull/2659

View File

@ -47,7 +47,6 @@ impl fmt::Debug for Error {
impl StdError for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
// TODO: populate if replacement for Box<dyn Error> is found
None
}
}

View File

@ -6,7 +6,7 @@
//
// See <https://github.com/rust-lang/rust/issues/83375>
pub use actix_http::error::{
BlockingError, ContentTypeError, DispatchError, HttpError, ParseError, PayloadError,
ContentTypeError, DispatchError, HttpError, ParseError, PayloadError,
};
use derive_more::{Display, Error, From};
@ -33,6 +33,14 @@ pub(crate) use macros::{downcast_dyn, downcast_get_type_id};
/// This type alias is generally used to avoid writing out `actix_http::Error` directly.
pub type Result<T, E = Error> = std::result::Result<T, E>;
/// An error representing a problem running a blocking task on a thread pool.
#[derive(Debug, Display, Error)]
#[display(fmt = "Blocking thread pool is shut down unexpectedly")]
#[non_exhaustive]
pub struct BlockingError;
impl ResponseError for crate::error::BlockingError {}
/// Errors which can occur when attempting to generate resource uri.
#[derive(Debug, PartialEq, Display, Error, From)]
#[non_exhaustive]

View File

@ -6,20 +6,22 @@ use std::{
io::{self, Write as _},
};
use actix_http::{
body::BoxBody,
header::{self, TryIntoHeaderValue},
Response, StatusCode,
};
use actix_http::Response;
use bytes::BytesMut;
use crate::{
body::BoxBody,
error::{downcast_dyn, downcast_get_type_id},
helpers, HttpResponse,
helpers,
http::{
header::{self, TryIntoHeaderValue},
StatusCode,
},
HttpResponse,
};
/// Errors that can generate responses.
// TODO: add std::error::Error bound when replacement for Box<dyn Error> is found
// TODO: flesh out documentation
pub trait ResponseError: fmt::Debug + fmt::Display {
/// Returns appropriate status code for error.
///
@ -73,7 +75,6 @@ impl ResponseError for std::str::Utf8Error {
impl ResponseError for std::io::Error {
fn status_code(&self) -> StatusCode {
// TODO: decide if these errors should consider not found or permission errors
match self.kind() {
io::ErrorKind::NotFound => StatusCode::NOT_FOUND,
io::ErrorKind::PermissionDenied => StatusCode::FORBIDDEN,
@ -86,7 +87,6 @@ impl ResponseError for actix_http::error::HttpError {}
impl ResponseError for actix_http::Error {
fn status_code(&self) -> StatusCode {
// TODO: map error kinds to status code better
StatusCode::INTERNAL_SERVER_ERROR
}
@ -107,8 +107,6 @@ impl ResponseError for actix_http::error::ParseError {
}
}
impl ResponseError for actix_http::error::BlockingError {}
impl ResponseError for actix_http::error::PayloadError {
fn status_code(&self) -> StatusCode {
match *self {

View File

@ -2,5 +2,4 @@
pub mod header;
// TODO: figure out how best to expose http::Error vs actix_http::Error
pub use actix_http::{uri, ConnectionType, Error, KeepAlive, Method, StatusCode, Uri, Version};