Deliver enum channel as both numeric and stringified

This commit is contained in:
Dominik Werder
2024-09-03 16:33:40 +02:00
parent 4cc0f65a0b
commit 55b3bf4acd
21 changed files with 712 additions and 204 deletions

View File

@@ -81,29 +81,14 @@ pub fn internal_error() -> http::Response<StreamBody> {
}
pub fn error_response(msg: String, reqid: impl AsRef<str>) -> http::Response<StreamBody> {
let status = StatusCode::INTERNAL_SERVER_ERROR;
let js = serde_json::json!({
"message": msg.to_string(),
"requestid": reqid.as_ref(),
});
if let Ok(body) = serde_json::to_string_pretty(&js) {
match Response::builder()
.status(status)
.header(http::header::CONTENT_TYPE, APP_JSON)
.body(body_string(body))
{
Ok(res) => res,
Err(e) => {
error!("can not generate http error response {e}");
internal_error()
}
}
} else {
internal_error()
}
error_status_response(StatusCode::INTERNAL_SERVER_ERROR, msg, reqid)
}
pub fn not_found_response(msg: String, reqid: impl AsRef<str>) -> http::Response<StreamBody> {
let status = StatusCode::NOT_FOUND;
error_status_response(StatusCode::NOT_FOUND, msg, reqid)
}
pub fn error_status_response(status: StatusCode, msg: String, reqid: impl AsRef<str>) -> http::Response<StreamBody> {
let js = serde_json::json!({
"message": msg.to_string(),
"requestid": reqid.as_ref(),