Deliver enum channel as both numeric and stringified
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user