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 have implemented WebResponseError for serde errors, but I found that the return result is not what I expected. I always feel that ntex serializes JSON data during route parsing, not when using function parameters in the processor. When I want to know, how can I capture serialization errors and convert them into the results I want before returning them。
Thank you for your reply. I don't know where to capture deserialization errors. I thought I had implemented web:: error:: Webex ResponseError to capture the errors I wanted in the processor. Looking forward to your reply.
Here is my test code:
use ntex::web;
use ntex::web::middleware::Logger;
use ntex::web::types::Json;
use serde::Deserialize;
mod apps;
use crate::apps::apperr::AppErr;
#[ntex::main]
async fn main()->Result<(), std::io::Error> {
std::env::set_var("RUST_LOG", "info");
env_logger::init();
web::HttpServer::new(
||{
web::App::new()
.wrap(Logger::default())
.service(
web::scope("/").route("/", web::post().to(index))
)
}
)
.bind("127.0.0.1:3000")?
.run()
.await
}
#[derive(Debug,Deserialize)]
struct UserInfo{
name:String,
pwd:String,
}
async fn index(info:Json<UserInfo>)->Result<String,AppErr>{
println!("name:{},password:{}",info.name,info.pwd);
Ok(format!("Hi {}",info.name))
}
I have implemented WebResponseError for serde errors, but I found that the return result is not what I expected. I always feel that ntex serializes JSON data during route parsing, not when using function parameters in the processor. When I want to know, how can I capture serialization errors and convert them into the results I want before returning them。
This is my incorrect implementation
The text was updated successfully, but these errors were encountered: