1// This file is part of Substrate.
23// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
56// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
1011// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
1516// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
1819//! Mixnet RPC module errors.
2021use jsonrpsee::types::error::{ErrorObject, ErrorObjectOwned};
22use sc_mixnet::{PostErr, RemoteErr, TopologyErr};
2324/// Mixnet RPC error type.
25pub struct Error(pub sc_mixnet::Error);
2627/// Base code for all mixnet errors.
28const BASE_ERROR: i32 = crate::error::base::MIXNET;
2930impl From<Error> for ErrorObjectOwned {
31fn from(err: Error) -> Self {
32let code = match err.0 {
33 sc_mixnet::Error::ServiceUnavailable => BASE_ERROR + 1,
34 sc_mixnet::Error::NoReply => BASE_ERROR + 2,
35 sc_mixnet::Error::BadReply => BASE_ERROR + 3,
36 sc_mixnet::Error::Post(PostErr::TooManyFragments) => BASE_ERROR + 101,
37 sc_mixnet::Error::Post(PostErr::SessionMixnodesNotKnown(_)) => BASE_ERROR + 102,
38 sc_mixnet::Error::Post(PostErr::SessionDisabled(_)) => BASE_ERROR + 103,
39 sc_mixnet::Error::Post(PostErr::Topology(TopologyErr::NoConnectedGatewayMixnodes)) =>
40 BASE_ERROR + 151,
41 sc_mixnet::Error::Post(PostErr::Topology(_)) => BASE_ERROR + 150,
42 sc_mixnet::Error::Post(_) => BASE_ERROR + 100,
43 sc_mixnet::Error::Remote(RemoteErr::Other(_)) => BASE_ERROR + 200,
44 sc_mixnet::Error::Remote(RemoteErr::Decode(_)) => BASE_ERROR + 201,
45 };
46 ErrorObject::owned(code, err.0.to_string(), None::<()>)
47 }
48}