fire_http_api/
error.rs

1use std::fmt::{Debug, Display};
2
3pub use fire::header::StatusCode;
4
5use representation::request::{DeserializeError, SerializeError};
6use serde::Serialize;
7
8/*
9Errors we encounter at the moment
10
11headers_missing
12
13deserialize error
14
15serialize error
16
17
18*/
19
20/// The error that is sent if something goes wrong while responding
21/// to a request.
22/// ## Panics
23/// If deserialization or serialization failes
24/// this will result in a panic
25pub trait ApiError: Debug + Display + Serialize {
26	fn from_error(e: Error) -> Self;
27
28	fn status_code(&self) -> StatusCode;
29}
30
31#[derive(Debug, thiserror::Error)]
32#[non_exhaustive]
33pub enum Error {
34	/// Some headers are missing
35	///
36	/// Not all headers from this list might be missing
37	#[error("Headers missing: {0:?}")]
38	HeadersMissing(&'static [&'static str]),
39
40	/// Deserialization failed
41	#[error("Deserialize error: {0}")]
42	Deserialize(DeserializeError),
43
44	/// Serialization failed
45	#[error("Serialize error: {0}")]
46	Serialize(SerializeError),
47
48	#[error("Extraction error: {0}")]
49	ExtractionError(Box<dyn std::error::Error + Send + Sync>),
50
51	/// Some internal Error
52	#[error("Internal error: {0}")]
53	Fire(fire::Error),
54}