mirror of
https://github.com/actix/actix-extras.git
synced 2025-02-23 10:53:02 +01:00
Update to actix-web 4.0.0-beta.7. (#24)
Add two new error types implementing ResponseError, as required, for our extractors. Add public docs for new errors. Co-authored-by: LukeMathWalker <rust@lpalmieri.com>
This commit is contained in:
parent
077bb85088
commit
0034e3bda8
@ -24,8 +24,8 @@ opentelemetry_0_13 = ["opentelemetry", "tracing-opentelemetry"]
|
|||||||
emit_event_on_error = []
|
emit_event_on_error = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "=4.0.0-beta.6"
|
actix-web = "=4.0.0-beta.7"
|
||||||
actix-http = "=3.0.0-beta.6"
|
actix-http = "=3.0.0-beta.7"
|
||||||
actix-service = "^2.0.0"
|
actix-service = "^2.0.0"
|
||||||
tracing = "0.1.19"
|
tracing = "0.1.19"
|
||||||
tracing-futures = "0.2.4"
|
tracing-futures = "0.2.4"
|
||||||
|
@ -7,7 +7,7 @@ edition = "2018"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4.0.0-beta.6"
|
actix-web = "4.0.0-beta.7"
|
||||||
opentelemetry = { version = "0.13", features = ["rt-tokio-current-thread"] }
|
opentelemetry = { version = "0.13", features = ["rt-tokio-current-thread"] }
|
||||||
opentelemetry-jaeger = { version = "0.12", features = ["tokio"] }
|
opentelemetry-jaeger = { version = "0.12", features = ["tokio"] }
|
||||||
tracing-opentelemetry = { version = "0.12" }
|
tracing-opentelemetry = { version = "0.12" }
|
||||||
|
@ -7,7 +7,7 @@ edition = "2018"
|
|||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "=4.0.0-beta.6"
|
actix-web = "=4.0.0-beta.7"
|
||||||
tracing = "0.1.19"
|
tracing = "0.1.19"
|
||||||
opentelemetry = { version = "0.13", features = ["rt-tokio-current-thread"] }
|
opentelemetry = { version = "0.13", features = ["rt-tokio-current-thread"] }
|
||||||
opentelemetry-jaeger = { version = "0.12", features = ["tokio"] }
|
opentelemetry-jaeger = { version = "0.12", features = ["tokio"] }
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use actix_web::dev::Payload;
|
use actix_web::dev::Payload;
|
||||||
use actix_web::{FromRequest, HttpRequest};
|
use actix_web::{FromRequest, HttpRequest, ResponseError};
|
||||||
use std::future::{ready, Ready};
|
use std::future::{ready, Ready};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@ -54,11 +54,47 @@ impl std::fmt::Display for RequestId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl FromRequest for RequestId {
|
impl FromRequest for RequestId {
|
||||||
type Error = ();
|
type Error = RequestIdExtractionError;
|
||||||
type Future = Ready<Result<Self, Self::Error>>;
|
type Future = Ready<Result<Self, Self::Error>>;
|
||||||
type Config = ();
|
type Config = ();
|
||||||
|
|
||||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||||
ready(req.extensions().get::<RequestId>().copied().ok_or(()))
|
ready(
|
||||||
|
req.extensions()
|
||||||
|
.get::<RequestId>()
|
||||||
|
.copied()
|
||||||
|
.ok_or(RequestIdExtractionError { _priv: () }),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// Error returned by the [`RequestId`] extractor when it fails to retrieve
|
||||||
|
/// the current request id from request-local storage.
|
||||||
|
///
|
||||||
|
/// It only happens if you try to extract the current request id without having
|
||||||
|
/// registered [`TracingLogger`] as a middleware for your application.
|
||||||
|
///
|
||||||
|
/// [`TracingLogger`]: crate::TracingLogger
|
||||||
|
pub struct RequestIdExtractionError {
|
||||||
|
// It turns out that a unit struct has a public constructor!
|
||||||
|
// Therefore adding fields to it (either public or private) later on
|
||||||
|
// is an API breaking change.
|
||||||
|
// Therefore we are adding a dummy private field that the compiler is going
|
||||||
|
// to optimise away to make sure users cannot construct this error
|
||||||
|
// manually in their own code.
|
||||||
|
_priv: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ResponseError for RequestIdExtractionError {}
|
||||||
|
|
||||||
|
impl std::fmt::Display for RequestIdExtractionError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"Failed to retrieve request id from request-local storage."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for RequestIdExtractionError {}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use actix_web::dev::Payload;
|
use actix_web::dev::Payload;
|
||||||
use actix_web::{FromRequest, HttpRequest};
|
use actix_web::{FromRequest, HttpRequest, ResponseError};
|
||||||
use std::future::{ready, Ready};
|
use std::future::{ready, Ready};
|
||||||
use tracing::Span;
|
use tracing::Span;
|
||||||
|
|
||||||
@ -47,11 +47,47 @@ impl std::convert::Into<Span> for RootSpan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromRequest for RootSpan {
|
impl FromRequest for RootSpan {
|
||||||
type Error = ();
|
type Error = RootSpanExtractionError;
|
||||||
type Future = Ready<Result<Self, Self::Error>>;
|
type Future = Ready<Result<Self, Self::Error>>;
|
||||||
type Config = ();
|
type Config = ();
|
||||||
|
|
||||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||||
ready(req.extensions().get::<RootSpan>().cloned().ok_or(()))
|
ready(
|
||||||
|
req.extensions()
|
||||||
|
.get::<RootSpan>()
|
||||||
|
.cloned()
|
||||||
|
.ok_or(RootSpanExtractionError { _priv: () }),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// Error returned by the [`RootSpan`] extractor when it fails to retrieve
|
||||||
|
/// the root span from request-local storage.
|
||||||
|
///
|
||||||
|
/// It only happens if you try to extract the root span without having
|
||||||
|
/// registered [`TracingLogger`] as a middleware for your application.
|
||||||
|
///
|
||||||
|
/// [`TracingLogger`]: crate::TracingLogger
|
||||||
|
pub struct RootSpanExtractionError {
|
||||||
|
// It turns out that a unit struct has a public constructor!
|
||||||
|
// Therefore adding fields to it (either public or private) later on
|
||||||
|
// is an API breaking change.
|
||||||
|
// Therefore we are adding a dummy private field that the compiler is going
|
||||||
|
// to optimise away to make sure users cannot construct this error
|
||||||
|
// manually in their own code.
|
||||||
|
_priv: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ResponseError for RootSpanExtractionError {}
|
||||||
|
|
||||||
|
impl std::fmt::Display for RootSpanExtractionError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"Failed to retrieve the root span from request-local storage."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for RootSpanExtractionError {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user