MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / error_response

Function error_response

vmm/src/api/http/mod.rs:80–102  ·  view source on GitHub ↗
(error: HttpError, status: StatusCode)

Source from the content-addressed store, hash-verified

78/// simplicity.
79#[allow(clippy::needless_pass_by_value)]
80pub fn error_response(error: HttpError, status: StatusCode) -> Response {
81 let mut response = Response::new(Version::Http11, status);
82
83 let error: &dyn Error = &error;
84 // Write the Display::display() output all errors (from top to root).
85 let error_messages = std::iter::successors(Some(error), |sub_error| {
86 // Dereference necessary to mitigate rustc compiler bug.
87 // See <https://github.com/rust-lang/rust/issues/141673>
88 (*sub_error).source()
89 })
90 .map(|error| format!("{error}"))
91 .collect::<Vec<_>>();
92
93 info!("HTTP API error response: {}", error_messages.join(": "));
94
95 // TODO: Move `api` module from `vmm` to dedicated crate and use a common type definition
96 let json = serde_json::to_string(&error_messages).unwrap();
97
98 let body = Body::new(json);
99 response.set_body(body);
100
101 response
102}
103
104/// An HTTP endpoint handler interface
105pub trait EndpointHandler {

Callers 3

handle_requestMethod · 0.85
handle_http_requestFunction · 0.85
handle_requestMethod · 0.85

Calls 3

newFunction · 0.85
sourceMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected