mirror of
https://github.com/fafhrd91/actix-web
synced 2024-12-12 15:30:23 +01:00
update migration guide
This commit is contained in:
parent
09cffc093c
commit
e942d3e3b1
@ -31,6 +31,7 @@ Headings marked with :warning: are **breaking behavioral changes**. They will pr
|
|||||||
- [Returning `HttpResponse` synchronously](#returning-httpresponse-synchronously)
|
- [Returning `HttpResponse` synchronously](#returning-httpresponse-synchronously)
|
||||||
- [`#[actix_web::main]` and `#[tokio::main]`](#actix_webmain-and-tokiomain)
|
- [`#[actix_web::main]` and `#[tokio::main]`](#actix_webmain-and-tokiomain)
|
||||||
- [`web::block`](#webblock)
|
- [`web::block`](#webblock)
|
||||||
|
-
|
||||||
|
|
||||||
## MSRV
|
## MSRV
|
||||||
|
|
||||||
@ -483,3 +484,24 @@ The `web::block` helper has changed return type from roughly `async fn(fn() -> R
|
|||||||
- let n: u32 = web::block(|| Ok(123)).await?;
|
- let n: u32 = web::block(|| Ok(123)).await?;
|
||||||
+ let n: u32 = web::block(|| Ok(123)).await??;
|
+ let n: u32 = web::block(|| Ok(123)).await??;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## `HttpResponse` as a `ResponseError`
|
||||||
|
|
||||||
|
The implementation of `ResponseError` for `HttpResponse` has been removed.
|
||||||
|
|
||||||
|
It was common in v3 to use `HttpResponse` as an error type in fallible handlers. The problem is that `HttpResponse` contains no knowledge or reference to the source error. Being able to guarantee that an "error" response actually contains an error reference makes middleware and other parts of Actix Web more effective.
|
||||||
|
|
||||||
|
The error response builders in the `error` module were available in v3 but are now the best method for simple error responses without requiring you to implement the trait on your own custom error types. These builders can receive simple strings and third party errors that can not implement the `ResponseError` trait.
|
||||||
|
|
||||||
|
A few common patterns are affected by this change:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- Err(HttpResponse::InternalServerError().finish())
|
||||||
|
+ Err(error::ErrorInternalServerError("reason"))
|
||||||
|
|
||||||
|
- Err(HttpResponse::InternalServerError().body(third_party_error.to_string()))
|
||||||
|
+ Err(error::ErrorInternalServerError(err))
|
||||||
|
|
||||||
|
- .map_err(|err| HttpResponse::InternalServerError().finish())?
|
||||||
|
+ .map_err(error::ErrorInternalServerError)?
|
||||||
|
```
|
||||||
|
@ -5,10 +5,7 @@ use actix_utils::future::{err, ok, Ready};
|
|||||||
use futures_core::future::LocalBoxFuture;
|
use futures_core::future::LocalBoxFuture;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{dev::Payload, error, Error, FromRequest, HttpRequest};
|
||||||
dev::Payload, error::ErrorInternalServerError, extract::FromRequest, request::HttpRequest,
|
|
||||||
Error,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Data factory.
|
/// Data factory.
|
||||||
pub(crate) trait DataFactory {
|
pub(crate) trait DataFactory {
|
||||||
@ -160,7 +157,7 @@ impl<T: ?Sized + 'static> FromRequest for Data<T> {
|
|||||||
req.match_name().unwrap_or_else(|| req.path())
|
req.match_name().unwrap_or_else(|| req.path())
|
||||||
);
|
);
|
||||||
|
|
||||||
err(ErrorInternalServerError(
|
err(error::ErrorInternalServerError(
|
||||||
"Requested application data is not configured correctly. \
|
"Requested application data is not configured correctly. \
|
||||||
View/enable debug logs for more details.",
|
View/enable debug logs for more details.",
|
||||||
))
|
))
|
||||||
|
@ -11,3 +11,6 @@
|
|||||||
## Error Propagation
|
## Error Propagation
|
||||||
|
|
||||||
## When To (Not) Use Middleware
|
## When To (Not) Use Middleware
|
||||||
|
|
||||||
|
## Author's References
|
||||||
|
- `EitherBody` + when is middleware appropriate: https://discord.com/channels/771444961383153695/952016890723729428
|
||||||
|
Loading…
Reference in New Issue
Block a user