forked from lightningdevkit/ldk-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
79 lines (78 loc) · 3.6 KB
/
Copy patherror.rs
File metadata and controls
79 lines (78 loc) · 3.6 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
// This file is Copyright its original authors, visible in version control
// history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// You may not use this file except in accordance with one or both of these
// licenses.
/// When HttpStatusCode is not ok (200), the response `content` contains a serialized `ErrorResponse`
/// with the relevant ErrorCode and `message`
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorResponse {
/// The error message containing a generic description of the error condition in English.
/// It is intended for a human audience only and should not be parsed to extract any information
/// programmatically. Client-side code may use it for logging only.
#[prost(string, tag = "1")]
pub message: ::prost::alloc::string::String,
/// The error code uniquely identifying an error condition.
/// It is meant to be read and understood programmatically by code that detects/handles errors by
/// type.
///
/// **Caution**: If a new type of `error_code` is introduced in the `ErrorCode` enum, `error_code` field will be set to
/// `UnknownError`.
#[prost(enumeration = "ErrorCode", tag = "2")]
pub error_code: i32,
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum ErrorCode {
/// Will never be used as `error_code` by server.
///
/// **Caution**: If a new type of `error_code` is introduced in the `ErrorCode` enum, `error_code` field will be set to
/// `UnknownError`.
UnknownError = 0,
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
InvalidRequestError = 1,
/// Used when authentication fails or in case of an unauthorized request.
AuthError = 2,
/// Used to represent an error while doing a Lightning operation.
LightningError = 3,
/// Used when an internal server error occurred. The client is probably at no fault.
InternalServerError = 4,
}
impl ErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
ErrorCode::UnknownError => "UNKNOWN_ERROR",
ErrorCode::InvalidRequestError => "INVALID_REQUEST_ERROR",
ErrorCode::AuthError => "AUTH_ERROR",
ErrorCode::LightningError => "LIGHTNING_ERROR",
ErrorCode::InternalServerError => "INTERNAL_SERVER_ERROR",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN_ERROR" => Some(Self::UnknownError),
"INVALID_REQUEST_ERROR" => Some(Self::InvalidRequestError),
"AUTH_ERROR" => Some(Self::AuthError),
"LIGHTNING_ERROR" => Some(Self::LightningError),
"INTERNAL_SERVER_ERROR" => Some(Self::InternalServerError),
_ => None,
}
}
}