-
Notifications
You must be signed in to change notification settings - Fork 2
/
Errors.mo
88 lines (84 loc) · 3.27 KB
/
Errors.mo
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
80
81
82
83
84
85
86
87
88
import Principal "mo:base/Principal";
import Nat64 "mo:base/Nat64";
import Types "Types";
module {
public type WsError = {
#AnonymousPrincipalNotAllowed;
#ClientKeyAlreadyConnected : {
client_key : Types.ClientKey;
};
#ClientKeyMessageMismatch : {
client_key : Types.ClientKey;
};
#ClientKeyNotConnected : {
client_key : Types.ClientKey;
};
#ClientNotRegisteredToGateway : {
client_key : Types.ClientKey;
gateway_principal : Types.GatewayPrincipal;
};
#ClientPrincipalNotConnected : {
client_principal : Types.ClientPrincipal;
};
#DecodeServiceMessageContent : {
err : Text;
};
#ExpectedIncomingMessageToClientNumNotInitialized : {
client_key : Types.ClientKey;
};
#GatewayNotRegistered : {
gateway_principal : Types.GatewayPrincipal;
};
#InvalidServiceMessage;
#IncomingSequenceNumberWrong : {
expected_sequence_num : Nat64;
actual_sequence_num : Nat64;
};
#OutgoingMessageToClientNumNotInitialized : {
client_key : Types.ClientKey;
};
};
public func to_string(err : WsError) : Text {
switch (err) {
case (#AnonymousPrincipalNotAllowed) {
"Anonymous principal is not allowed";
};
case (#ClientKeyAlreadyConnected({ client_key })) {
"Client with key " # Types.clientKeyToText(client_key) # " already has an open connection";
};
case (#ClientKeyMessageMismatch({ client_key })) {
"Client with principal " # Principal.toText(client_key.client_principal) # " has a different key than the one used in the message";
};
case (#ClientKeyNotConnected({ client_key })) {
"Client with key " # Types.clientKeyToText(client_key) # " doesn't have an open connection";
};
case (#ClientNotRegisteredToGateway({ client_key; gateway_principal })) {
"Client with key " # Types.clientKeyToText(client_key) # " was not registered to gateway " # Principal.toText(gateway_principal);
};
case (#ClientPrincipalNotConnected({ client_principal })) {
"Client with principal " # Principal.toText(client_principal) # " doesn't have an open connection";
};
case (#DecodeServiceMessageContent({ err })) {
"Error decoding service message content: " # err;
};
case (#ExpectedIncomingMessageToClientNumNotInitialized({ client_key })) {
"Expected incoming message to client num not initialized for client key " # Types.clientKeyToText(client_key);
};
case (#GatewayNotRegistered({ gateway_principal })) {
"Gateway with principal " # Principal.toText(gateway_principal) # " is not registered";
};
case (#InvalidServiceMessage) {
"Invalid service message";
};
case (#IncomingSequenceNumberWrong({ expected_sequence_num; actual_sequence_num })) {
"Expected incoming sequence number " # Nat64.toText(expected_sequence_num) # " but got " # Nat64.toText(actual_sequence_num);
};
case (#OutgoingMessageToClientNumNotInitialized({ client_key })) {
"Outgoing message to client num not initialized for client key " # Types.clientKeyToText(client_key);
};
};
};
public func to_string_result(err : WsError) : Types.Result<(), Text> {
#Err(to_string(err));
};
};