You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suppose one possible solution would be to add a match branch to separate the deserialization errors, something like this:
.map(|res:Result<T,_>| match res {Ok(data) => data.validate().map(|_| Json(data)).map_err(Error::from),Err(actix_web::error::JsonPayloadError::Deserialize(e)) => Err(Error::from(e)),// will use From<serde_json::error::Error for ErrorErr(e) => Err(Error::from(e)),// will use From<actix_web::error::JsonPayloadError> for Error (like before)})
Please note that this is hypothetical, I haven't tested the above code at all. 🙂
FWIW, any deserialization error that occurs for Path or Query does result in the correct Error::Deserialize(_) variant being used.
The text was updated successfully, but these errors were encountered:
In my code, I created a function to allow me to write a custom error handler for JSON data validation errors. It includes something like this:
I was expected that any error occurring during JSON deserialization (missing field, etc.) would result in an
Error::Deserialize(DeserializeErrors::DeserializeJson(_))
. However, this is not the case - instead, I get anError::JsonPayloadError(JsonPayloadError::Deserialize(_))
.I believe this is caused by this code:
actix-web-validator/src/json.rs
Lines 131 to 134 in b8ffc17
In this
match
'sErr(e)
branch,e
is anactix_web::error::JsonPayloadError
. Thus,Error::from
will use theFrom
implementation forJsonPayloadError
, resulting in anError::JsonPayloadError
.I suppose one possible solution would be to add a
match
branch to separate the deserialization errors, something like this:Please note that this is hypothetical, I haven't tested the above code at all. 🙂
FWIW, any deserialization error that occurs for
Path
orQuery
does result in the correctError::Deserialize(_)
variant being used.The text was updated successfully, but these errors were encountered: