1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01:00

fix typos in guide

This commit is contained in:
Nikolay Kim 2017-12-20 23:27:30 -08:00
parent 55534bff8c
commit 0567e6fb0a
2 changed files with 8 additions and 6 deletions

View File

@ -57,7 +57,7 @@ struct MyObj {
name: &'static str,
}
/// we have to convert Error into HttpResponse as well
/// Responder
impl Responder for MyObj {
type Item = HttpResponse;
type Error = Error;
@ -72,6 +72,7 @@ impl Responder for MyObj {
}
}
/// Because `MyObj` implements `Responder`, it is possible to return it directly
fn index(req: HttpRequest) -> MyObj {
MyObj{name: "user"}
}

View File

@ -35,9 +35,9 @@ fn index(req: HttpRequest) -> io::Result<fs::NamedFile> {
## Custom error response
To add support for custom errors all we need to do just implement `ResponseError` trait.
`ResponseError` trait has default implementation for `error_response()` method, it
generates *500* response.
To add support for custom errors, all we need to do is just implement `ResponseError` trait
for custom error. `ResponseError` trait has default implementation
for `error_response()` method, it generates *500* response.
```rust
# extern crate actix_web;
@ -50,6 +50,7 @@ struct MyError {
name: &'static str
}
/// Use default implementation for `error_response()` method
impl error::ResponseError for MyError {}
fn index(req: HttpRequest) -> Result<&'static str, MyError> {
@ -64,7 +65,7 @@ fn index(req: HttpRequest) -> Result<&'static str, MyError> {
```
In this example *index* handler will always return *500* response. But it is easy
to return different responses.
to return different responses for different type of errors.
```rust
# extern crate actix_web;
@ -132,4 +133,4 @@ fn index(req: HttpRequest) -> Result<&'static str> {
# }
```
In this example *BAD REQUEST* response get generated for `MYError` error.
In this example *BAD REQUEST* response get generated for `MyError` error.