1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-18 15:41:17 +00:00

added some error logging for extractors: Data, Json, Query, and Path (#765)

* added some error logging for extractors

* changed log::error to log::debug and fixed position of log for path

* added request path to debug logs
This commit is contained in:
Darin 2019-04-10 15:45:13 -04:00 committed by Nikolay Kim
parent 9d82d4dfb9
commit 6ab9838977
3 changed files with 12 additions and 1 deletions

View file

@ -96,6 +96,8 @@ impl<T: 'static, P> FromRequest<P> for Data<T> {
if let Some(st) = req.app_config().extensions().get::<Data<T>>() { if let Some(st) = req.app_config().extensions().get::<Data<T>>() {
Ok(st.clone()) Ok(st.clone())
} else { } else {
log::debug!("Failed to construct App-level Data extractor. \
Request path: {:?}", req.path());
Err(ErrorInternalServerError( Err(ErrorInternalServerError(
"App data is not configured, to configure use App::data()", "App data is not configured, to configure use App::data()",
)) ))
@ -235,6 +237,7 @@ impl<T: 'static, P> FromRequest<P> for RouteData<T> {
if let Some(st) = req.route_data::<T>() { if let Some(st) = req.route_data::<T>() {
Ok(st.clone()) Ok(st.clone())
} else { } else {
log::debug!("Failed to construct Route-level Data extractor");
Err(ErrorInternalServerError( Err(ErrorInternalServerError(
"Route data is not configured, to configure use Route::data()", "Route data is not configured, to configure use Route::data()",
)) ))

View file

@ -179,10 +179,14 @@ where
.map(|c| (c.limit, c.ehandler.clone())) .map(|c| (c.limit, c.ehandler.clone()))
.unwrap_or((32768, None)); .unwrap_or((32768, None));
let path = req.path().to_string();
Box::new( Box::new(
JsonBody::new(req, payload) JsonBody::new(req, payload)
.limit(limit) .limit(limit)
.map_err(move |e| { .map_err(move |e| {
log::debug!("Failed to deserialize Json from payload. \
Request path: {:?}", path);
if let Some(err) = err { if let Some(err) = err {
(*err)(e, &req2) (*err)(e, &req2)
} else { } else {

View file

@ -122,6 +122,10 @@ where
fn from_request(req: &HttpRequest, _: &mut Payload<P>) -> Self::Future { fn from_request(req: &HttpRequest, _: &mut Payload<P>) -> Self::Future {
serde_urlencoded::from_str::<T>(req.query_string()) serde_urlencoded::from_str::<T>(req.query_string())
.map(|val| Ok(Query(val))) .map(|val| Ok(Query(val)))
.unwrap_or_else(|e| Err(e.into())) .unwrap_or_else(|e| {
log::debug!("Failed during Query extractor deserialization. \
Request path: {:?}", req.path());
Err(e.into())
})
} }
} }