From 0f86c596fac4f29e367cc2c0528e1d81a0bbcbde Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 5 Apr 2018 21:54:39 -0400 Subject: [PATCH] Tweaks to Errors chapter. --- guide/src/qs_4_5.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/guide/src/qs_4_5.md b/guide/src/qs_4_5.md index cf8c6ef36..4bc82451d 100644 --- a/guide/src/qs_4_5.md +++ b/guide/src/qs_4_5.md @@ -1,10 +1,11 @@ # Errors -Actix uses [`Error` type](../actix_web/error/struct.Error.html) +Actix uses the [`Error` type](../actix_web/error/struct.Error.html) and [`ResponseError` trait](../actix_web/error/trait.ResponseError.html) for handling handler's errors. + Any error that implements the `ResponseError` trait can be returned as an error value. -*Handler* can return an *Result* object; actix by default provides +`Handler` can return an `Result` object. By default, actix provides a `Responder` implementation for compatible result types. Here is the implementation definition: @@ -12,7 +13,8 @@ definition: impl> Responder for Result ``` -And any error that implements `ResponseError` can be converted into an `Error` object. +Any error that implements `ResponseError` can be converted into an `Error` object. + For example, if the *handler* function returns `io::Error`, it would be converted into an `HttpInternalServerError` response. Implementation for `io::Error` is provided by default. @@ -35,7 +37,7 @@ fn index(req: HttpRequest) -> io::Result { ## Custom error response -To add support for custom errors, all we need to do is just implement the `ResponseError` trait +To add support for custom errors, all we need to do is implement the `ResponseError` trait for the custom error type. The `ResponseError` trait has a default implementation for the `error_response()` method: it generates a *500* response. @@ -109,7 +111,7 @@ fn index(req: HttpRequest) -> Result<&'static str, MyError> { ## Error helpers Actix provides a set of error helper types. It is possible to use them for generating -specific error responses. We can use helper types for the first example with custom error. +specific error responses. We can use the helper types for the first example with a custom error. ```rust # extern crate actix_web;