Files
nym/clients/native/websocket-requests/src/error.rs
T
Jędrzej Stuczyński e5afd54ce0 Feature/node status api (#680)
* Basic storage stub

* New models for new node status api

* Route handling

* Mounting new routes

* Missing selective commit

* Moved network monitor related files to separate package

* Starting to see some sqlx action

* Schema updates

* Log statement upon finished migration

* Removed old diesel related imports

* Converted mixnode cache initialisation into a fairing

* Moved cache related functionalities to separate package

Also defined staging there

* Created run method for validator cache + removed unwrap

* Removed old node-status-api types and left bunch of todo placeholders in their place

* Fixed managing validatorcache

* Status reports are starting to get constructed

* Submitting some dummy results to the database

* Removing duplicate code for generating reports

* Removed statuses older than 48h

* Initial attempt at trying to obtain reports for all active nodes

* Removed duplicates from the full report

* Grabbing uptime history

* Updating historical uptimes of active nodes

* Updated sqlx-data.json

* Removed all placeholder foomp owner values

* Changed Layer serde behaviour for easier usage

* Extended validator api config

* Initial (seems working !) integration with network monitor

* Added database path configuration to config

* Using ValidatorCache in NetworkMonitor

* Flag indicating whether validator cache has been initialised

* Introduced a locla-only route for reward script to perform daily chores

* Flag to save config to a file

* Moved spawning of receiving future to run method rather than new

* Removed arguments that dont make sense to be configured via CLI

* Removed dead code from config file

* More dead code removal

* Added validator API to CI

* Corrected manifest-path arguments

* Constructing network monitor by passing config

* Combined validator API CI with the main CI file

* Using query_as for NodeStatus

* Checking if historical uptimes were already calculated on particular day

* Making id field NOT NULL

* More query_as! action

* Updated sqlx-data.json

* Removed unused chrono feature

* Renamed the migration file

* Changed default validator endpoint to point to local validator

* Removing unnecessary clone

* More appropriate naming

* Removed dead code

* Lock file updates

* Updated network monitor address in contract code

* Don't stage node status api if network monitor is disabled

* cargo fmt

* Updated all license notices to SPDX
2021-07-19 14:02:47 +01:00

82 lines
2.4 KiB
Rust

// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use serde::{Deserialize, Serialize};
use std::fmt;
// no need to go fancy here like we've done in other places.
#[derive(PartialEq, Clone, Serialize, Deserialize)]
pub struct Error {
pub kind: ErrorKind,
pub message: String,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", self.kind.as_str(), self.message)
}
}
impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl Error {
pub fn new(kind: ErrorKind, message: String) -> Self {
Error { kind, message }
}
}
#[repr(u8)]
#[derive(PartialEq, Clone, Serialize, Deserialize)]
pub enum ErrorKind {
/// The received request contained no data.
EmptyRequest = 0x01,
/// The received request did not contain enough data to be fully parsed.
TooShortRequest = 0x02,
/// The received request tag is not defined.
UnknownRequest = 0x03,
/// The received request is malformed.
MalformedRequest = 0x04,
// that's an arbitrary division but let's keep 1-127 (hex 0x01 - 0x7F) values request-specific
// and 128-254 (hex 0x80 - 0xFE) for responses
/// The received response contained no data.
EmptyResponse = 0x80,
/// The received response did not contain enough data to be fully parsed.
TooShortResponse = 0x81,
/// The received response tag is not defined.
UnknownResponse = 0x82,
/// The received response is malformed.
MalformedResponse = 0x83,
/// The error is due to something else.
Other = 0xFF,
}
impl ErrorKind {
pub(crate) fn as_str(&self) -> &'static str {
match *self {
ErrorKind::EmptyRequest => "received request contained no data",
ErrorKind::TooShortRequest => "received request did not contain enough data",
ErrorKind::UnknownRequest => "unknown request type",
ErrorKind::MalformedRequest => "malformed request",
ErrorKind::EmptyResponse => "received response contained no data",
ErrorKind::TooShortResponse => "received response did not contain enough data",
ErrorKind::UnknownResponse => "unknown response type",
ErrorKind::MalformedResponse => "malformed response",
ErrorKind::Other => "other",
}
}
}