nautilus_tardis/common/error.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Adapter-level error types aggregating HTTP and Machine Server errors.
17
18/// Adapter-level error aggregating HTTP and WebSocket errors.
19#[derive(Debug, thiserror::Error)]
20pub enum TardisError {
21 /// An HTTP API error.
22 #[error("HTTP error: {0}")]
23 Http(#[from] crate::http::error::Error),
24
25 /// A Machine Server WebSocket error.
26 #[error("Machine error: {0}")]
27 Machine(#[from] crate::machine::Error),
28}
29
30impl TardisError {
31 /// Returns `true` if the error is likely transient and the operation can be
32 /// retried.
33 #[must_use]
34 pub fn is_retryable(&self) -> bool {
35 match self {
36 Self::Http(crate::http::error::Error::ApiError { status, .. }) => {
37 *status == 429 || *status >= 500
38 }
39 Self::Http(crate::http::error::Error::Request(_)) => true,
40 Self::Machine(crate::machine::Error::ConnectFailed(_)) => true,
41 Self::Machine(crate::machine::Error::ConnectionClosed { .. }) => true,
42 _ => false,
43 }
44 }
45}