1use std::fmt;
2use http::{StatusCode, uri::{InvalidUri, InvalidUriParts}};
3
4#[derive(Debug, Eq, PartialEq)]
5pub enum Error {
6 Response(StatusCode),
7 Internal(String),
8}
9
10impl fmt::Display for Error {
11 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12 write!(f, "{:?}", self)
13 }
14}
15
16impl std::error::Error for Error {}
17
18impl From<std::io::Error> for Error {
19 fn from(err: std::io::Error) -> Self {
20 Self::Internal(err.to_string())
21 }
22}
23
24impl From<std::string::FromUtf8Error> for Error {
25 fn from(err: std::string::FromUtf8Error) -> Self {
26 Self::Internal(err.to_string())
27 }
28}
29
30impl From<StatusCode> for Error {
31 fn from(err: StatusCode) -> Self {
32 Self::Response(err)
33 }
34}
35
36impl From<InvalidUri> for Error {
37 fn from(err: InvalidUri) -> Self {
38 Self::Internal(err.to_string())
39 }
40}
41
42impl From<InvalidUriParts> for Error {
43 fn from(err: InvalidUriParts) -> Self {
44 Self::Internal(err.to_string())
45 }
46}
47
48impl From<hyper::Error> for Error {
49 fn from(err: hyper::Error) -> Self {
50 Self::Internal(err.to_string())
51 }
52}
53
54impl From<hyper::header::InvalidHeaderValue> for Error {
55 fn from(err: hyper::header::InvalidHeaderValue) -> Self {
56 Self::Internal(err.to_string())
57 }
58}
59
60impl From<serde_json::Error> for Error {
61 fn from(err: serde_json::Error) -> Self {
62 Self::Internal(err.to_string())
63 }
64}