Skip to main content

ErrorCode

Struct ErrorCode 

Source
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

Source

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");
Source

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);
Source

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");
Source

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.

Source

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.

Source

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)));
Source

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");
Source

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);
Source

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);

Trait Implementations§

Source§

impl Clone for ErrorCode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ErrorCode

Source§

impl Debug for ErrorCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ErrorCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ErrorCode

Source§

impl Hash for ErrorCode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ErrorCode

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ErrorCode

Auto Trait Implementations§

§

impl Forget for ErrorCode

§

impl Freeze for ErrorCode
where &'static str: Freeze,

§

impl Move for ErrorCode

§

impl RefUnwindSafe for ErrorCode

§

impl Send for ErrorCode
where &'static str: Send,

§

impl Sync for ErrorCode

§

impl Unpin for ErrorCode
where &'static str: Unpin,

§

impl UnsafeUnpin for ErrorCode
where &'static str: UnsafeUnpin,

§

impl UnwindSafe for ErrorCode
where &'static str: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.