scratchstack_errors/lib.rs
1#![warn(clippy::all)]
2#![deny(rustdoc::missing_crate_level_docs)]
3#![deny(rustdoc::broken_intra_doc_links)]
4#![deny(missing_docs)]
5
6//! The `ServiceError` trait used throughout Scratchstack libraries.
7
8use {http::status::StatusCode, std::error::Error};
9
10/// A trait for errors that can be converted to an HTTP response and a string error code.
11///
12/// Error codes typically are more descriptive than HTTP status reasons. The [AWS Identity and Access Management
13/// Common Errors](https://docs.aws.amazon.com/IAM/latest/APIReference/CommonErrors.html) reference has examples of
14/// typical error codes, including `IncompleteSignature`, `InvalidAction`, `InvalidClientTokenId`,
15/// `InvalidParameterCombination`, etc.
16pub trait ServiceError: Error {
17 /// The string status code for this error.
18 fn error_code(&self) -> &'static str;
19
20 /// The HTTP status code for this error.
21 fn http_status(&self) -> StatusCode;
22}