Struct dropshot::HttpError [−][src]
HttpError
represents an error generated as part of handling an API
request. When these bubble up to the top of the request handling stack
(which is most of the time that they're generated), these are turned into an
HTTP response, which includes:
- a status code, which is likely either 400-level (indicating a client error, like bad input) or 500-level (indicating a server error).
- a structured (JSON) body, which includes:
- a string error code, which identifies the underlying error condition so that clients can potentially make programmatic decisions based on the error type
- a string error message, which is the human-readable summary of the issue, intended to make sense for API users (i.e., not API server developers)
- optionally: additional metadata describing the issue. For a validation error, this could include information about which parameter was invalid and why. This should conform to a schema associated with the error code.
It's easy to go overboard with the error codes and metadata. Generally, we should avoid creating specific codes and metadata unless there's a good reason for a client to care.
Besides that, HttpError
s also have an internal error message, which may
differ from the error message that gets reported to users. For example, if
the request fails because an internal database is unreachable, the client may
just see "internal error", while the server log would include more details
like "failed to acquire connection to database at 10.1.2.3".
Fields
status_code: StatusCode
HTTP status code for this error
error_code: Option<String>
Optional string error code for this error. Callers are advised to use an enum to populate this field.
external_message: String
Error message to be sent to API client for this error
internal_message: String
Error message recorded in the log for this error
Implementations
impl HttpError
[src]
pub fn for_client_error(
error_code: Option<String>,
status_code: StatusCode,
message: String
) -> Self
[src]
error_code: Option<String>,
status_code: StatusCode,
message: String
) -> Self
Generates an HttpError
for any 400-level client error with a custom
message
used for both the internal and external message. The
expectation here is that for most 400-level errors, there's no need for a
separate internal message.
pub fn for_internal_error(internal_message: String) -> Self
[src]
Generates an HttpError
for a 500 "Internal Server Error" error with the
given internal_message
for the internal message.
pub fn for_unavail(error_code: Option<String>, internal_message: String) -> Self
[src]
Generates an HttpError
for a 503 "Service Unavailable" error with the
given internal_message
for the internal message.
pub fn for_bad_request(error_code: Option<String>, message: String) -> Self
[src]
Generates a 400 "Bad Request" error with the given message
used for
both the internal and external message. This is a convenience wrapper
around HttpError::for_client_error
.
pub fn for_status(error_code: Option<String>, status_code: StatusCode) -> Self
[src]
Generates an HttpError
for the given HTTP status_code
where the
internal and external messages for the error come from the standard label
for this status code (e.g., the message for status code 404 is "Not
Found").
pub fn for_not_found(
error_code: Option<String>,
internal_message: String
) -> Self
[src]
error_code: Option<String>,
internal_message: String
) -> Self
Generates an HttpError
for a 404 "Not Found" error with a custom
internal message internal_message
. The external message will be "Not
Found" (i.e., the standard label for status code 404).
pub fn into_response(self, request_id: &str) -> Response<Body>
[src]
Generates an HTTP response for the given HttpError
, using request_id
for the response's request id.
Trait Implementations
impl Debug for HttpError
[src]
impl From<Error> for HttpError
[src]
fn from(error: HyperError) -> Self
[src]
impl From<Error> for HttpError
[src]
Auto Trait Implementations
impl RefUnwindSafe for HttpError
[src]
impl Send for HttpError
[src]
impl Sync for HttpError
[src]
impl Unpin for HttpError
[src]
impl UnwindSafe for HttpError
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SendSyncUnwindSafe for T where
T: Send + Sync + UnwindSafe + ?Sized,
[src]
T: Send + Sync + UnwindSafe + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,