+ Added Response::RestrictedInput to db-lib

Should make it more dsecriptive with really weird input and prevent even more confusing 500 responses to the client

+ db-lib::Channels::add now also potentially returns this new RestrictedInput variant
This commit is contained in:
shockrah
2020-12-29 23:50:57 -08:00
parent b7209c000c
commit 549c69f668
3 changed files with 24 additions and 10 deletions

View File

@@ -5,7 +5,7 @@ use hyper::{
use mysql_async::Pool;
use serde_json::{Value, to_string};
use serde_json::{json, Value, to_string};
use db::{
self,
@@ -62,13 +62,24 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
*response.body_mut() = Body::from(to_string(&row).unwrap_or("{}".into()));
},
// user error that the db doesn't deal with so we just blame the user
db::Response::RestrictedInput(msg) => {
*response.status_mut() = StatusCode::BAD_REQUEST;
response.headers_mut().insert("Content-Type",
HeaderValue::from_static("application/json"));
let bjson = json!({"error": msg});
*response.body_mut() = Body::from(to_string(&bjson).unwrap_or("{}".into()));
},
// inserted but could not fetch
db::Response::Empty => *response.status_mut() = StatusCode::NOT_FOUND,
// TODO: loggin
//like legit issues past here
db::Response::Other(msg) => {
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
eprintln!("\t{}", msg);
}
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; // conn issue probably
eprintln!("\t[ Channels ] {}", msg);
},
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR // ngmi
}
}
},