mirror of
https://github.com/mozilla-services/syncstorage-rs.git
synced 2026-05-05 20:26:26 +02:00
refactor: convert actix web middleware to async await (#1338)
Refactored Box::pin to replace and_then() calls to use async move Closes 545
This commit is contained in:
parent
75e5f273ab
commit
f76b5fc675
@ -7,7 +7,7 @@ use actix_web::{
|
||||
web::Data,
|
||||
Error, HttpMessage,
|
||||
};
|
||||
use futures::future::{self, LocalBoxFuture, TryFutureExt};
|
||||
use futures::future::{self, LocalBoxFuture};
|
||||
use sentry::protocol::Event;
|
||||
use std::task::Poll;
|
||||
|
||||
@ -85,7 +85,10 @@ where
|
||||
.app_data::<Data<ServerState>>()
|
||||
.map(|state| Metrics::from(state.get_ref()));
|
||||
|
||||
Box::pin(self.service.call(sreq).and_then(move |mut sresp| {
|
||||
let fut = self.service.call(sreq);
|
||||
|
||||
Box::pin(async move {
|
||||
let mut sresp = fut.await?;
|
||||
// handed an actix_error::error::Error;
|
||||
// Fetch out the tags (in case any have been added.) NOTE: request extensions
|
||||
// are NOT automatically passed to responses. You need to check both.
|
||||
@ -142,14 +145,14 @@ where
|
||||
}
|
||||
if !apie.is_reportable() {
|
||||
trace!("Sentry: Not reporting error: {:?}", apie);
|
||||
return future::ok(sresp);
|
||||
return Ok(sresp);
|
||||
}
|
||||
report(&tags, event_from_error(apie));
|
||||
}
|
||||
}
|
||||
}
|
||||
future::ok(sresp)
|
||||
}))
|
||||
Ok(sresp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use actix_web::{
|
||||
@ -7,7 +8,7 @@ use actix_web::{
|
||||
Error,
|
||||
};
|
||||
|
||||
use futures::future::{self, LocalBoxFuture, TryFutureExt};
|
||||
use futures::future::{self, LocalBoxFuture};
|
||||
use syncstorage_db_common::util::SyncTimestamp;
|
||||
|
||||
use crate::error::{ApiError, ApiErrorKind};
|
||||
@ -38,13 +39,12 @@ where
|
||||
}
|
||||
|
||||
let ts = SyncTimestamp::default().as_seconds();
|
||||
Box::pin(self.service.call(sreq).and_then(move |mut resp| {
|
||||
future::ready(
|
||||
set_weave_timestamp(resp.headers_mut(), ts)
|
||||
.map_err(Into::into)
|
||||
.map(|_| resp),
|
||||
)
|
||||
}))
|
||||
let fut = self.service.call(sreq);
|
||||
Box::pin(async move {
|
||||
let mut resp = fut.await?;
|
||||
set_weave_timestamp(resp.headers_mut(), ts)?;
|
||||
Ok(resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user