1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use thiserror::Error;
use url::ParseError;

use crate::jwt;

#[derive(Debug, Error)]
pub enum ParamError {
  #[error("Invalid params for {msg}")]
  InvalidParams { msg: String },
}

#[derive(Debug, Error)]
pub enum ClientError {
  #[error(transparent)]
  /// Thrown when JWT signing fails
  JwtError(#[from] jwt::JwtError),

  #[error(transparent)]
  /// Thrown when Token fails
  TokenError(#[from] jsonwebtoken::errors::Error),

  #[error(transparent)]
  /// Thrown when submitting a POST/GET request fails
  ReqwestError(#[from] reqwest::Error),
}

#[derive(Debug, Error)]
pub enum FireblocksError {
  #[error(transparent)]
  /// Thrown when JWT signing fails
  JwtError(#[from] jwt::JwtError),

  #[error("Deserialization Error: {err}. Response: {text}")]
  /// Serde JSON Error
  SerdeJson { request_id: String, err: serde_json::Error, text: String },

  #[error(transparent)]
  /// Thrown when submitting a POST/GET request fails
  ReqwestError(#[from] reqwest::Error),

  #[error(transparent)]
  UrlError(#[from] ParseError),

  #[error(transparent)]
  QueryParamError(#[from] ParamError),

  #[error("Internal Fireblocks Error. HTTP Code {code} {text} request_id:{request_id}")]
  InternalError { request_id: String, path: String, code: u16, text: String },

  #[error("{path} not found. request_id: {request_id}")]
  NotFound { request_id: String, path: String },

  #[error("Bad Request for {path} {text} request_id: {request_id}")]
  BadRequest { request_id: String, path: String, text: String },

  #[error("Unauthorized for {path} {text} request_id: {request_id}")]
  Unauthorized { request_id: String, path: String, text: String },

  #[error("Forbidden for {path} {text} request_id: {request_id}")]
  Forbidden { request_id: String, path: String, text: String },

  #[error("Unknown Error HTTP Code: {code} request_id: {request_id}")]
  Unknown { request_id: String, path: String, code: u16, text: String },

  #[error("Invalid Request Error: {text}. Code: {code} request_id: {request_id}")]
  InvalidRequest { request_id: String, code: u16, text: String },
}