style: cleanup UTF8 error throwing code

This commit is contained in:
DarkCat09 2024-06-03 16:36:43 +04:00
parent 803acce7e9
commit 19a4e0c299
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3
2 changed files with 2 additions and 8 deletions

View file

@ -45,7 +45,7 @@ pub enum AppError {
}, },
#[display(fmt = "UTF8")] #[display(fmt = "UTF8")]
Utf8Error(std::str::Utf8Error), Utf8Error(#[from] std::str::Utf8Error),
#[display(fmt = "IDK")] #[display(fmt = "IDK")]
UnknownBody { UnknownBody {

View file

@ -5,7 +5,6 @@ pub mod qs_parser;
use crate::ingest_protocol::NMJsonPacket; use crate::ingest_protocol::NMJsonPacket;
use crate::web_server::app_error::AppError; use crate::web_server::app_error::AppError;
use bstr::ByteSlice;
use ntex::http::{HttpMessage, StatusCode}; use ntex::http::{HttpMessage, StatusCode};
use ntex::util::Bytes; use ntex::util::Bytes;
use ntex::web::types::State; use ntex::web::types::State;
@ -50,12 +49,7 @@ pub async fn device_handler<'a>(
Err(error) => json_error = Some(error), Err(error) => json_error = Some(error),
}, },
"application/x-www-form-urlencoded" => { "application/x-www-form-urlencoded" => {
let body = match std::str::from_utf8(body.as_ref()) { let body = std::str::from_utf8(body.as_ref())?;
Ok(body) => body,
Err(error) => {
return Err(AppError::Utf8Error(error));
}
};
match qs_parser::parse_nm_qs_format(body).await { match qs_parser::parse_nm_qs_format(body).await {
Ok(qs_body) => { Ok(qs_body) => {
real_body = Some(NMJsonPacket { real_body = Some(NMJsonPacket {