Skip to main content

error_body_response

Function error_body_response 

Source
pub fn error_body_response(
    status: StatusCode,
    body: &Value,
) -> Response<Full<Bytes>>
Expand description

Wrap an arbitrary JSON value as a full HTTP response with the given status.

ยงExamples

use guardrail_proxy::error::error_body_response;
use hyper::StatusCode;

let body = serde_json::json!({"error": {"code": "prompt_injection"}});
let resp = error_body_response(StatusCode::FORBIDDEN, &body);
assert_eq!(resp.status(), StatusCode::FORBIDDEN);