jsonrpsee_core/client/error.rs
1// Copyright 2019-2021 Parity Technologies (UK) Ltd.
2//
3// Permission is hereby granted, free of charge, to any
4// person obtaining a copy of this software and associated
5// documentation files (the "Software"), to deal in the
6// Software without restriction, including without
7// limitation the rights to use, copy, modify, merge,
8// publish, distribute, sublicense, and/or sell copies of
9// the Software, and to permit persons to whom the Software
10// is furnished to do so, subject to the following
11// conditions:
12//
13// The above copyright notice and this permission notice
14// shall be included in all copies or substantial portions
15// of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25// DEALINGS IN THE SOFTWARE.
26
27//! Error type for client(s).
28
29use crate::{BoxError, RegisterMethodError, params::EmptyBatchRequest};
30use jsonrpsee_types::{ErrorObjectOwned, InvalidRequestId};
31use std::sync::Arc;
32
33/// Error type.
34#[derive(Debug, thiserror::Error)]
35pub enum Error {
36 /// JSON-RPC error which can occur when a JSON-RPC call fails.
37 #[error("{0}")]
38 Call(#[from] ErrorObjectOwned),
39 /// Networking error or error on the low-level protocol layer.
40 #[error(transparent)]
41 Transport(BoxError),
42 /// The background task has been terminated.
43 #[error("The background task closed {0}; restart required")]
44 RestartNeeded(Arc<Error>),
45 /// Failed to parse the data.
46 #[error("Parse error: {0}")]
47 ParseError(#[from] serde_json::Error),
48 /// Invalid subscription ID.
49 #[error("Invalid subscription ID")]
50 InvalidSubscriptionId,
51 /// Invalid request ID.
52 #[error(transparent)]
53 InvalidRequestId(#[from] InvalidRequestId),
54 /// Request timeout
55 #[error("Request timeout")]
56 RequestTimeout,
57 /// Custom error.
58 #[error("Custom error: {0}")]
59 Custom(String),
60 /// Not implemented for HTTP clients.
61 #[error("Not implemented")]
62 HttpNotImplemented,
63 /// Empty batch request.
64 #[error(transparent)]
65 EmptyBatchRequest(#[from] EmptyBatchRequest),
66 /// The error returned when registering a method or subscription failed.
67 #[error(transparent)]
68 RegisterMethod(#[from] RegisterMethodError),
69 /// An internal state when the underlying RpcService
70 /// got disconnected and the error must be fetched
71 /// from the backend.
72 //
73 // NOTE: This is a workaround where an error occurred in
74 // underlying RpcService implementation in the async client
75 // but we don't want to expose different error types for
76 // ergonomics when writing middleware.
77 #[error("RPC service disconnected")]
78 #[doc(hidden)]
79 ServiceDisconnect,
80}