in identity/aziot-identityd/src/http/mod.rs [30:75]
fn to_http_error(err: &crate::Error) -> http_common::server::Error {
let error_message = http_common::server::error_to_message(err);
// TODO: When we get distributed tracing, associate these logs with the tracing ID.
for line in error_message.lines() {
log::log!(
match err {
crate::Error::Internal(_) => log::Level::Error,
_ => log::Level::Info,
},
"!!! {}",
line,
);
}
match err {
// Do not use error_message because we don't want to leak internal errors to the client.
// Just return the top-level error, ie "internal error"
crate::Error::Internal(_) => http_common::server::Error {
status_code: hyper::StatusCode::INTERNAL_SERVER_ERROR,
message: err.to_string().into(),
},
crate::error::Error::InvalidParameter(_, _)
| crate::error::Error::DeviceNotFound
| crate::error::Error::ModuleNotFound => http_common::server::Error {
status_code: hyper::StatusCode::BAD_REQUEST,
message: error_message.into(),
},
crate::error::Error::DpsClient(_)
| crate::error::Error::DpsNotSupportedInNestedMode
| crate::error::Error::HubClient(_)
| crate::error::Error::KeyClient(_) => http_common::server::Error {
status_code: hyper::StatusCode::NOT_FOUND,
message: error_message.into(),
},
crate::error::Error::Authentication | crate::error::Error::Authorization => {
http_common::server::Error {
status_code: hyper::StatusCode::UNAUTHORIZED,
message: error_message.into(),
}
}
}
}