2023-05-20 14:27:34 +00:00
|
|
|
// Copyright (C) 2023-2099 The crate authors.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Affero General Public License as published by the
|
|
|
|
// Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
// option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
use std::error::Error as StdError;
|
|
|
|
use std::str::Utf8Error;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub(crate) enum Error {
|
2023-05-20 17:34:08 +00:00
|
|
|
MethodMismatch,
|
|
|
|
InvalidToken,
|
|
|
|
InvalidContentType,
|
|
|
|
Hyper(hyper::Error),
|
|
|
|
SerdeJson(serde_json::Error),
|
|
|
|
Utf8(Utf8Error),
|
2023-05-20 14:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl StdError for Error {}
|
|
|
|
|
|
|
|
impl std::fmt::Display for Error {
|
2023-05-20 17:34:08 +00:00
|
|
|
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
Error::MethodMismatch => write!(fmt, "the method is invalid"),
|
|
|
|
Error::InvalidToken => write!(fmt, "the token is invalid"),
|
|
|
|
Error::InvalidContentType => write!(fmt, "the content-type is invalid"),
|
|
|
|
Error::Hyper(e) => write!(fmt, "hyper error: {}", e),
|
|
|
|
Error::SerdeJson(e) => write!(fmt, "serde_json error: {}", e),
|
|
|
|
Error::Utf8(e) => write!(fmt, "Utf8 error: {}", e),
|
|
|
|
}
|
|
|
|
}
|
2023-05-20 14:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<hyper::Error> for Error {
|
2023-05-20 17:34:08 +00:00
|
|
|
fn from(err: hyper::Error) -> Error {
|
|
|
|
Error::Hyper(err)
|
|
|
|
}
|
2023-05-20 14:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<serde_json::Error> for Error {
|
2023-05-20 17:34:08 +00:00
|
|
|
fn from(err: serde_json::Error) -> Error {
|
|
|
|
Error::SerdeJson(err)
|
|
|
|
}
|
2023-05-20 14:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Utf8Error> for Error {
|
2023-05-20 17:34:08 +00:00
|
|
|
fn from(err: Utf8Error) -> Error {
|
|
|
|
Error::Utf8(err)
|
|
|
|
}
|
2023-05-20 14:27:34 +00:00
|
|
|
}
|