tide_disco/error.rs
1// Copyright (c) 2022 Espresso Systems (espressosys.com)
2// This file is part of the tide-disco library.
3
4// You should have received a copy of the MIT License
5// along with the tide-disco library. If not, see <https://mit-license.org/>.
6
7pub use disco_types::error::*;
8
9pub trait ErrorExt {
10 fn into_tide_error(self) -> tide::Error;
11 fn from_server_error(source: tide::Error) -> Self;
12}
13
14impl<E: Error> ErrorExt for E {
15 fn into_tide_error(self) -> tide::Error {
16 tide::Error::new(self.status(), self)
17 }
18
19 fn from_server_error(source: tide::Error) -> Self {
20 match source.downcast::<Self>() {
21 Ok(err) => err,
22 Err(source) => Self::catch_all(source.status().into(), source.to_string()),
23 }
24 }
25}