1use std::fmt;
4
5use thiserror::Error;
6
7#[derive(Debug, Error)]
10pub enum AvailabilityError {
11 #[error("{0}")]
12 NotFound(String),
13 #[error("{0}")]
14 RangeExceeded(String),
15 #[error("{0}")]
16 BadRequest(String),
17}
18
19#[derive(Debug)]
21pub enum ApiError {
22 BadRequest(anyhow::Error),
24 NotFound(anyhow::Error),
26 Internal(anyhow::Error),
28}
29
30impl fmt::Display for ApiError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 ApiError::BadRequest(err) | ApiError::NotFound(err) | ApiError::Internal(err) => {
34 write!(f, "{}", err)
35 },
36 }
37 }
38}
39
40impl std::error::Error for ApiError {
41 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
42 match self {
43 ApiError::BadRequest(err) | ApiError::NotFound(err) | ApiError::Internal(err) => {
44 err.source()
45 },
46 }
47 }
48}