1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5 MissingLambdaContext,
6 InvalidEnvironmentConfig(&'static str),
7 #[cfg(feature = "db")]
8 DatabaseFailure(sqlx::Error),
9}
10
11impl fmt::Display for Error {
12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13 match self {
14 Error::MissingLambdaContext => {
15 write!(f, "`EndpointMetadata` is missing the AWS Lambda Context")
16 }
17 Error::InvalidEnvironmentConfig(err_msg) => {
18 write!(f, "Invalid Environment Config: {err_msg}")
19 }
20 #[cfg(feature = "db")]
21 Error::DatabaseFailure(err) => {
22 write!(f, "Database Failure: {err}")
23 }
24 }
25 }
26}
27
28impl std::error::Error for Error {
29 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
30 match self {
31 #[cfg(feature = "db")]
32 Error::DatabaseFailure(e) => Some(e),
33
34 _ => None,
35 }
36 }
37}
38
39#[cfg(feature = "db")]
40impl From<sqlx::Error> for Error {
41 fn from(e: sqlx::Error) -> Self {
42 Error::DatabaseFailure(e)
43 }
44}