mirror of
https://github.com/actix/actix-website
synced 2024-11-23 16:31:08 +01:00
Docs update and ci bumped up hugo version (#138)
This commit is contained in:
parent
4fffc16668
commit
58341eca3a
@ -15,7 +15,7 @@ cache:
|
||||
- $TRAVIS_BUILD_DIR/examples/target
|
||||
|
||||
install:
|
||||
- curl -L https://github.com/gohugoio/hugo/releases/download/v0.40.3/hugo_0.40.3_Linux-64bit.tar.gz | tar xzvf -
|
||||
- curl -L https://github.com/gohugoio/hugo/releases/download/v0.62.1/hugo_0.62.1_Linux-64bit.tar.gz | tar xzvf -
|
||||
|
||||
matrix:
|
||||
include:
|
||||
|
@ -12,15 +12,12 @@ from web handlers.
|
||||
|
||||
If a handler returns an `Error` (referring to the [general Rust trait
|
||||
`std::error::Error`][stderror]) in a `Result` that also implements the
|
||||
`ResponseError` trait, actix-web will render that error as an HTTP response.
|
||||
`ResponseError` has a single function called `error_response()` that returns
|
||||
`HttpResponse`:
|
||||
`ResponseError` trait, actix-web will render that error as an HTTP response with it's corresponding [`actix_web::http::StatusCode`][status_code]. Internal server error is generated by default:
|
||||
|
||||
```rust
|
||||
pub trait ResponseError: Fail {
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
}
|
||||
pub trait ResponseError {
|
||||
fn error_response(&self) -> HttpResponse;
|
||||
fn status_code(&self) -> StatusCode;
|
||||
}
|
||||
```
|
||||
|
||||
@ -55,7 +52,7 @@ Here's an example implementation for `ResponseError`:
|
||||
{{< include-example example="errors" file="main.rs" section="response-error" >}}
|
||||
|
||||
`ResponseError` has a default implementation for `error_response()` that will
|
||||
render a *500* (internal server error), and that's what will happen when the
|
||||
render a _500_ (internal server error), and that's what will happen when the
|
||||
`index` handler executes above.
|
||||
|
||||
Override `error_response()` to produce more useful results:
|
||||
@ -66,7 +63,7 @@ Override `error_response()` to produce more useful results:
|
||||
|
||||
Actix-web provides a set of error helper functions that are useful for generating
|
||||
specific HTTP error codes from other errors. Here we convert `MyError`, which
|
||||
doesn't implement the `ResponseError` trait, to a *400* (bad request) using
|
||||
doesn't implement the `ResponseError` trait, to a _400_ (bad request) using
|
||||
`map_err`:
|
||||
|
||||
{{< include-example example="errors" file="helpers.rs" section="helpers" >}}
|
||||
@ -78,7 +75,7 @@ for a full list of available error helpers.
|
||||
|
||||
Actix-web provides automatic compatibility with the [failure] library so that
|
||||
errors deriving `fail` will be converted automatically to an actix error. Keep
|
||||
in mind that those errors will render with the default *500* status code unless you
|
||||
in mind that those errors will render with the default _500_ status code unless you
|
||||
also provide your own `error_response()` implementation for them.
|
||||
|
||||
# Error logging
|
||||
@ -140,3 +137,4 @@ This is a basic example using `middleware::Logger`:
|
||||
[responseerror]: https://docs.rs/actix-web/2/actix_web/error/trait.ResponseError.html
|
||||
[responseerrorimpls]: https://docs.rs/actix-web/2/actix_web/error/trait.ResponseError.html#foreign-impls
|
||||
[stderror]: https://doc.rust-lang.org/std/error/trait.Error.html
|
||||
[status_code]: https://docs.rs/actix-web/2.0.0/actix_web/http/struct.StatusCode.html
|
||||
|
@ -20,6 +20,14 @@ cd hello-world
|
||||
Now, add `actix-web` as a dependency of your project by ensuring your `Cargo.toml`
|
||||
contains the following:
|
||||
|
||||
```ini
|
||||
[dependencies]
|
||||
actix-web = "{{< actix-version "actix-web" >}}"
|
||||
```
|
||||
|
||||
If you want to use the `#[actix_rt::main]` macro, you have to add `actix-rt` to your dependency.
|
||||
Now your `Cargo.toml` should look like following:
|
||||
|
||||
```ini
|
||||
[dependencies]
|
||||
actix-web = "{{< actix-version "actix-web" >}}"
|
||||
|
Loading…
Reference in New Issue
Block a user