pub struct ErrorCode { /* private fields */ }Expand description
An error code and the HTTP status it is sent with.
Every Stratum error response is {"error":{"code","message"}}. The codes
defined before Step 3a are written by the crate that sends them. This
type gives the codes Step 3a adds one definition, shared by the
controller and the gate that send them and the client that reads them.
§Examples
use stratum_node_core::ErrorCode;
assert_eq!(ErrorCode::SUSPENDED.as_str(), "suspended");
assert_eq!(ErrorCode::SUSPENDED.status(), 403);
assert_eq!(ErrorCode::from_code("archive_required"), Some(ErrorCode::ARCHIVE_REQUIRED));
assert_eq!(ErrorCode::from_code("conflict"), None);Implementations§
Source§impl ErrorCode
impl ErrorCode
Sourcepub const SUSPENDED: Self
pub const SUSPENDED: Self
suspended, 403: the requester, or the owner of the pod in the path,
is suspended. Also the answer to redeem and confirm by a
suspended key, decided before any stored response is looked up.
§Examples
use stratum_node_core::ErrorCode;
assert_eq!(ErrorCode::SUSPENDED.to_string(), "suspended");Sourcepub const ARCHIVE_REQUIRED: Self
pub const ARCHIVE_REQUIRED: Self
archive_required, 409: remove requires an archive, and none was
taken for the member’s current generation and suspension number.
§Examples
use stratum_node_core::ErrorCode;
assert_eq!(ErrorCode::ARCHIVE_REQUIRED.status(), 409);Sourcepub const POD_DATA_PRESENT: Self
pub const POD_DATA_PRESENT: Self
pod_data_present, 409: an invitation or redemption for a removed
or cancelled key whose old pod data has not been purged.
§Examples
use stratum_node_core::ErrorCode;
assert_eq!(ErrorCode::POD_DATA_PRESENT.as_str(), "pod_data_present");Sourcepub const APP_FORBIDDEN: Self
pub const APP_FORBIDDEN: Self
app_forbidden, 403: an application key used on a route, listener or
pod it may not reach, or a member key sent to the gate’s proxy
listener.
Sourcepub const RATE_LIMITED: Self
pub const RATE_LIMITED: Self
rate_limited, 429: a principal, all application keys together, or
the whole node exceeded its signed-pod-request rate limit.
Sourcepub const ALL: [Self; 5]
pub const ALL: [Self; 5]
Every code this type defines.
§Examples
use stratum_node_core::ErrorCode;
assert!(ErrorCode::ALL.iter().all(|c| ErrorCode::from_code(c.as_str()) == Some(*c)));Sourcepub const fn as_str(self) -> &'static str
pub const fn as_str(self) -> &'static str
Returns the code as it appears in error.code.
§Examples
use stratum_node_core::ErrorCode;
assert_eq!(ErrorCode::POD_DATA_PRESENT.as_str(), "pod_data_present");Sourcepub const fn status(self) -> u16
pub const fn status(self) -> u16
Returns the HTTP status the code is sent with.
§Examples
use stratum_node_core::ErrorCode;
assert_eq!(ErrorCode::ARCHIVE_REQUIRED.status(), 409);Sourcepub fn from_code(code: &str) -> Option<Self>
pub fn from_code(code: &str) -> Option<Self>
Returns the code named code, if this type defines it. The match is
exact and case-sensitive.
§Examples
use stratum_node_core::ErrorCode;
assert_eq!(ErrorCode::from_code("suspended"), Some(ErrorCode::SUSPENDED));
assert_eq!(ErrorCode::from_code("Suspended"), None);