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

rework Rejection system #115

Merged
merged 1 commit into from Oct 20, 2018
Merged

rework Rejection system #115

merged 1 commit into from Oct 20, 2018

Conversation

seanmonstar
Copy link
Owner

@seanmonstar seanmonstar commented Oct 11, 2018

The Rejection type can now nest and combine arbitrary rejections,
so it is no longer bound to a small set of meanings. The ranking of
status codes is still used to determine which rejection gets priority.

A different priority can be implemented by handling rejections with
a Filter::recover, and searching for causes in order via
Rejection::find_cause.

  • Adds warp::reject::custom() to create a Rejection with
    any Into<Box<std::error::Error>>. These rejections should be
    handled with an eventual Filter::recover. Any unhandled
    custom rejections are considered a server error.
  • Deprecates Rejection::with. Use custom rejections instead.
  • Deprecates Rejection::into_cause, as it can no longer work. Always
    returns Err(Rejection).
  • Deprecates Rejection::json, since the format needed is too generic.
    The errors.rs example shows how to send custom JSON when recovering
    from rejections.
  • Deprecates warp::reject(), since it current signals a 400 Bad Request, but in newer versions, it will signal 404 Not Found.
    It's deprecated simply to warn that the semantics are changing,
    but the function won't actually go away.
  • Deprecates reject::bad_request(), reject::forbidden(), and
    reject::server_error(). Uses custom rejections instead.

@seanmonstar
Copy link
Owner Author

Having thought on this over the week, I've decided to remove the reject::status(code) part. The purpose of the rejections isn't to provide a mirror-ed Reply interface. It's simply a specialized error system to be used in warp. To customize how a rejection should be rendered, the Filter::recover combinator can be used to inspect rejections and create a Reply.

@seanmonstar
Copy link
Owner Author

Here's the updated change:


The Rejection type can now nest and combine arbitrary rejections,
so it is no longer bound to a small set of meanings. The ranking of
status codes is still used to determine which rejection gets priority.

A different priority can be implemented by handling rejections with
a Filter::recover, and searching for causes in order via
Rejection::find_cause.

  • Adds warp::reject::custom() to create a Rejection with
    any Into<Box<std::error::Error>>. These rejections should be
    handled with an eventual Filter::recover. Any unhandled
    custom rejections are considered a server error.
  • Deprecates Rejection::with. Use custom rejections instead.
  • Deprecates Rejection::into_cause, as it can no longer work. Always
    returns Err(Rejection).
  • Deprecates Rejection::json, since the format needed is too generic.
    The errors.rs example shows how to send custom JSON when recovering
    from rejections.
  • Deprecates warp::reject(), since it current signals a 400 Bad Request, but in newer versions, it will signal 404 Not Found.
    It's deprecated simply to warn that the semantics are changing,
    but the function won't actually go away.
  • Deprecates reject::bad_request(), reject::forbidden(), and
    reject::server_error(). Uses custom rejections instead.

The `Rejection` type can now nest and combine arbitrary rejections,
so it is no longer bound to a small set of meanings. The ranking of
status codes is still used to determine which rejection gets priority.

A different priority can be implemented by handling rejections with
a `Filter::recover`, and searching for causes in order via
`Rejection::find_cause`.

- Adds `warp::reject::custom()` to create a `Rejection` with
  any `Into<Box<std::error::Error>>`. These rejections should be
  handled with an eventual `Filter::recover`. Any unhandled
  custom rejections are considered a server error.
- Deprecates `Rejection::with`. Use custom rejections instead.
- Deprecates `Rejection::into_cause`, as it can no longer work. Always
  returns `Err(Rejection)`.
- Deprecates `Rejection::json`, since the format needed is too generic.
  The `errors.rs` example shows how to send custom JSON when recovering
  from rejections.
- Deprecates `warp::reject()`, since it current signals a `400 Bad
  Request`, but in newer versions, it will signal `404 Not Found`.
  It's deprecated simply to warn that the semantics are changing,
  but the function won't actually go away.
- Deprecates `reject::bad_request()`, `reject::forbidden()`, and
  `reject::server_error()`. Uses custom rejections instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant