mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-10 22:57:43 +00:00
vmm: api: Return complete error responses in handle_http_request()
Instead of responding only headers with error code, we now return complete error responses to HTTP requests with errors (e.g. undefined endpoints and InternalSeverError). Fixes: #472 Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
0728bece0c
commit
fbd1a6c5f1
@ -26,6 +26,12 @@ pub enum HttpError {
|
||||
/// Attempt to access unsupported HTTP method
|
||||
BadRequest,
|
||||
|
||||
/// Undefined endpoints
|
||||
NotFound,
|
||||
|
||||
/// Internal Server Error
|
||||
InternalServerError,
|
||||
|
||||
/// Could not create a VM
|
||||
VmCreate(ApiError),
|
||||
|
||||
@ -194,9 +200,12 @@ fn handle_http_request(
|
||||
let mut response = match HTTP_ROUTES.routes.get(&path) {
|
||||
Some(route) => match api_notifier.try_clone() {
|
||||
Ok(notifier) => route.handle_request(&request, notifier, api_sender.clone()),
|
||||
Err(_) => Response::new(Version::Http11, StatusCode::InternalServerError),
|
||||
Err(_) => error_response(
|
||||
HttpError::InternalServerError,
|
||||
StatusCode::InternalServerError,
|
||||
),
|
||||
},
|
||||
None => Response::new(Version::Http11, StatusCode::NotFound),
|
||||
None => error_response(HttpError::NotFound, StatusCode::NotFound),
|
||||
};
|
||||
|
||||
response.set_server("Cloud Hypervisor API");
|
||||
|
Loading…
Reference in New Issue
Block a user