mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-28 01:52:57 +01:00
fix typos in guide
This commit is contained in:
parent
55534bff8c
commit
0567e6fb0a
@ -57,7 +57,7 @@ struct MyObj {
|
|||||||
name: &'static str,
|
name: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// we have to convert Error into HttpResponse as well
|
/// Responder
|
||||||
impl Responder for MyObj {
|
impl Responder for MyObj {
|
||||||
type Item = HttpResponse;
|
type Item = HttpResponse;
|
||||||
type Error = Error;
|
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 {
|
fn index(req: HttpRequest) -> MyObj {
|
||||||
MyObj{name: "user"}
|
MyObj{name: "user"}
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,9 @@ fn index(req: HttpRequest) -> io::Result<fs::NamedFile> {
|
|||||||
|
|
||||||
## Custom error response
|
## Custom error response
|
||||||
|
|
||||||
To add support for custom errors all we need to do just implement `ResponseError` trait.
|
To add support for custom errors, all we need to do is just implement `ResponseError` trait
|
||||||
`ResponseError` trait has default implementation for `error_response()` method, it
|
for custom error. `ResponseError` trait has default implementation
|
||||||
generates *500* response.
|
for `error_response()` method, it generates *500* response.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
# extern crate actix_web;
|
# extern crate actix_web;
|
||||||
@ -50,6 +50,7 @@ struct MyError {
|
|||||||
name: &'static str
|
name: &'static str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Use default implementation for `error_response()` method
|
||||||
impl error::ResponseError for MyError {}
|
impl error::ResponseError for MyError {}
|
||||||
|
|
||||||
fn index(req: HttpRequest) -> Result<&'static str, 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
|
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
|
```rust
|
||||||
# extern crate actix_web;
|
# 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.
|
||||||
|
Loading…
Reference in New Issue
Block a user