Merge branch 'testing' into master

This commit is contained in:
shockrah
2020-08-22 15:58:13 -07:00
22 changed files with 545 additions and 523 deletions

38
server-api/src/common.rs Normal file
View File

@@ -0,0 +1,38 @@
use mysql_async::error::ServerError;
use hyper::{Body, Response, StatusCode};
use serde::Serialize;
use serde_json::to_string as json;
#[derive(Serialize)]
struct GenericErrData {
status: u16,
message: &'static str,
note: &'static str,
}
pub fn db_err_response_body(response: &mut Response<Body>, err: ServerError) {
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
match err.code {
// Duplicate unique value was (tried to be) inserted
1062 => {
let s = json(&GenericErrData {
status: 1062,
message: "Duplicate key was inserted and failed",
note: "Check parameters given"
}).unwrap();
*response.body_mut() = Body::from(s);
},
// Generic errors
_ => {
let s = json(&GenericErrData{
status: 500,
message: "Generic Backend error",
note:""
}).unwrap();
*response.body_mut() = Body::from(s);
}
}
}