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
//! Contains the types and functions needed to use the Decentraland RPC implementation.
// proto file definition doesn't have a package name, so it defaults to "_"
// TODO: scope the protcolol just to the crate
include!;
/// This trait should me implemented by the Error type returned in your server's procedures
///
/// # Example
///
/// ```
/// use dcl_rpc::rpc_protocol::{RemoteError, RemoteErrorResponse};
/// pub enum MyEnumOfErrors {
/// EntityNotFound,
/// DbError
/// }
///
/// impl RemoteErrorResponse for MyEnumOfErrors {
/// fn error_code(&self) -> u32 {
/// match self {
/// Self::EntityNotFound => 404,
/// Self::DbError => 500
/// }
/// }
///
/// fn error_message(&self) -> String {
/// match self {
/// Self::EntityNotFound => "The entity wasn't found".to_string(),
/// Self::DbError => "Internal Server Error".to_string()
/// }
/// }
/// }
///
/// let error: RemoteError = MyEnumOfErrors::EntityNotFound.into();
/// assert_eq!(error.error_code, 404);
/// assert_eq!(error.error_message, "The entity wasn't found")
/// ```
///
///
/// Every type which implements [`RemoteErrorResponse`], it can be turned into a [`RemoteError`]
/// This functions works for filling a [`RemoteError`]. This is needed because:
///
/// When a server procedure returns a custom type as an error, which has to implement [`RemoteErrorResponse`](`super::RemoteErrorResponse`).
///
/// That custom type is then turned into a [`RemoteError`] but without a "true" value (`0`) in the `message_identifier` field
///
/// Because at the moment of conversion, the `message_number` is not available so the [`RemoteError`] has to be filled then.
///
pub
/// Build the [`ServerReady`](`RpcMessageTypes::ServerReady`) message for the client
pub