Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement std::error::Error for our custom errors #1422

Merged
merged 1 commit into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changes

## [Unreleased]

### Changed

* Implement `std::error::Error` for our custom errors [#1422]

[#1422]: https://github.com/actix/actix-web/pull/1422

## [3.0.0-alpha.1] - 2020-03-11

### Added
Expand Down
8 changes: 8 additions & 0 deletions actix-http/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changes

## [Unreleased]

### Changed

* Implement `std::error::Error` for our custom errors [#1422]

[#1422]: https://github.com/actix/actix-web/pull/1422

## [2.0.0-alpha.2] - 2020-03-07

### Changed
Expand Down
8 changes: 8 additions & 0 deletions actix-http/src/client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub enum ConnectError {
Io(io::Error),
}

impl std::error::Error for ConnectError {}

impl From<actix_connect::ConnectError> for ConnectError {
fn from(err: actix_connect::ConnectError) -> ConnectError {
match err {
Expand Down Expand Up @@ -86,6 +88,8 @@ pub enum InvalidUrl {
HttpError(http::Error),
}

impl std::error::Error for InvalidUrl {}

/// A set of errors that can occur during request sending and response reading
#[derive(Debug, Display, From)]
pub enum SendRequestError {
Expand Down Expand Up @@ -115,6 +119,8 @@ pub enum SendRequestError {
Body(Error),
}

impl std::error::Error for SendRequestError {}

/// Convert `SendRequestError` to a server `Response`
impl ResponseError for SendRequestError {
fn status_code(&self) -> StatusCode {
Expand All @@ -139,6 +145,8 @@ pub enum FreezeRequestError {
Http(HttpError),
}

impl std::error::Error for FreezeRequestError {}

impl From<FreezeRequestError> for SendRequestError {
fn from(e: FreezeRequestError) -> Self {
match e {
Expand Down
4 changes: 4 additions & 0 deletions actix-http/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ pub enum PayloadError {
Io(io::Error),
}

impl std::error::Error for PayloadError {}

impl From<h2::Error> for PayloadError {
fn from(err: h2::Error) -> Self {
PayloadError::Http2Payload(err)
Expand Down Expand Up @@ -441,6 +443,8 @@ pub enum ContentTypeError {
UnknownEncoding,
}

impl std::error::Error for ContentTypeError {}

/// Return `BadRequest` for `ContentTypeError`
impl ResponseError for ContentTypeError {
fn status_code(&self) -> StatusCode {
Expand Down
2 changes: 2 additions & 0 deletions actix-http/src/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub enum ProtocolError {
Io(io::Error),
}

impl std::error::Error for ProtocolError {}

impl ResponseError for ProtocolError {}

/// Websocket handshake errors
Expand Down
8 changes: 8 additions & 0 deletions awc/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changes

## [Unreleased]

### Changed

* Implement `std::error::Error` for our custom errors [#1422]

[#1422]: https://github.com/actix/actix-web/pull/1422

## [2.0.0-alpha.1] - 2020-03-11

* Update `actix-http` dependency to 2.0.0-alpha.2
Expand Down
4 changes: 4 additions & 0 deletions awc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum WsClientError {
SendRequest(SendRequestError),
}

impl std::error::Error for WsClientError {}

impl From<InvalidUrl> for WsClientError {
fn from(err: InvalidUrl) -> Self {
WsClientError::SendRequest(err.into())
Expand All @@ -68,5 +70,7 @@ pub enum JsonPayloadError {
Payload(PayloadError),
}

impl std::error::Error for JsonPayloadError {}

/// Return `InternalServerError` for `JsonPayloadError`
impl ResponseError for JsonPayloadError {}
12 changes: 12 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub enum UrlGenerationError {
ParseError(UrlParseError),
}

impl std::error::Error for UrlGenerationError {}

/// `InternalServerError` for `UrlGeneratorError`
impl ResponseError for UrlGenerationError {}

Expand Down Expand Up @@ -51,6 +53,8 @@ pub enum UrlencodedError {
Payload(PayloadError),
}

impl std::error::Error for UrlencodedError {}

/// Return `BadRequest` for `UrlencodedError`
impl ResponseError for UrlencodedError {
fn status_code(&self) -> StatusCode {
Expand Down Expand Up @@ -79,6 +83,8 @@ pub enum JsonPayloadError {
Payload(PayloadError),
}

impl std::error::Error for JsonPayloadError {}

/// Return `BadRequest` for `JsonPayloadError`
impl ResponseError for JsonPayloadError {
fn error_response(&self) -> HttpResponse {
Expand All @@ -99,6 +105,8 @@ pub enum PathError {
Deserialize(serde::de::value::Error),
}

impl std::error::Error for PathError {}

/// Return `BadRequest` for `PathError`
impl ResponseError for PathError {
fn status_code(&self) -> StatusCode {
Expand All @@ -114,6 +122,8 @@ pub enum QueryPayloadError {
Deserialize(serde::de::value::Error),
}

impl std::error::Error for QueryPayloadError {}

/// Return `BadRequest` for `QueryPayloadError`
impl ResponseError for QueryPayloadError {
fn status_code(&self) -> StatusCode {
Expand All @@ -139,6 +149,8 @@ pub enum ReadlinesError {
ContentTypeError(ContentTypeError),
}

impl std::error::Error for ReadlinesError {}

/// Return `BadRequest` for `ReadlinesError`
impl ResponseError for ReadlinesError {
fn status_code(&self) -> StatusCode {
Expand Down