|
1 | 1 |
|
2 |
| -export class TimeoutError extends Error {}; |
3 |
| -export class UnexpectedHttpResponse extends Error {}; |
| 2 | +export class TimeoutError extends Error { |
| 3 | + |
| 4 | +}; |
| 5 | + |
| 6 | +export class UnexpectedHttpResponse extends Error { |
| 7 | + |
| 8 | + /** |
| 9 | + * An error which occurs when a Websocket HTTP upgrade fails due to receiving an unexpected response from the server. |
| 10 | + * |
| 11 | + * @param {string | undefined} message |
| 12 | + * @param {object} obj |
| 13 | + * @param {number} [obj.code] |
| 14 | + * @param {import('node:http').ClientRequest} obj.request |
| 15 | + * @param {import('node:http').IncomingMessage} obj.response |
| 16 | + */ |
| 17 | + constructor(message, {code, request, response}) { |
| 18 | + super(message); |
| 19 | + |
| 20 | + /** @type {number | undefined} */ |
| 21 | + this.code = code; |
| 22 | + |
| 23 | + /** @type {import('node:http').ClientRequest} */ |
| 24 | + this.request = request; |
| 25 | + |
| 26 | + /** @type {import('node:http').IncomingMessage} */ |
| 27 | + this.response = response; |
| 28 | + } |
| 29 | +}; |
4 | 30 |
|
5 | 31 | export class RPCError extends Error {
|
| 32 | + /** @const */ |
6 | 33 | rpcErrorMessage = '';
|
| 34 | + /** @const */ |
7 | 35 | rpcErrorCode = 'GenericError';
|
8 | 36 | }
|
| 37 | + |
9 | 38 | export class RPCGenericError extends RPCError {
|
| 39 | + /** @const */ |
10 | 40 | rpcErrorMessage = '';
|
| 41 | + /** @const */ |
11 | 42 | rpcErrorCode = 'GenericError';
|
12 |
| -}; |
| 43 | +} |
| 44 | + |
13 | 45 | export class RPCNotImplementedError extends RPCError {
|
| 46 | + /** @const */ |
14 | 47 | rpcErrorMessage = 'Requested method is not known';
|
| 48 | + /** @const */ |
15 | 49 | rpcErrorCode = 'NotImplemented';
|
16 |
| -}; |
| 50 | +} |
| 51 | + |
17 | 52 | export class RPCNotSupportedError extends RPCError {
|
| 53 | + /** @const */ |
18 | 54 | rpcErrorMessage = 'Requested method is recognised but not supported';
|
| 55 | + /** @const */ |
19 | 56 | rpcErrorCode = 'NotSupported';
|
20 |
| -}; |
| 57 | +} |
| 58 | + |
21 | 59 | export class RPCInternalError extends RPCError {
|
| 60 | + /** @const */ |
22 | 61 | rpcErrorMessage = 'An internal error occurred and the receiver was not able to process the requested method successfully';
|
| 62 | + /** @const */ |
23 | 63 | rpcErrorCode = 'InternalError';
|
24 |
| -}; |
| 64 | +} |
| 65 | + |
25 | 66 | export class RPCProtocolError extends RPCError {
|
| 67 | + /** @const */ |
26 | 68 | rpcErrorMessage = 'Payload for method is incomplete';
|
| 69 | + /** @const */ |
27 | 70 | rpcErrorCode = 'ProtocolError';
|
28 |
| -}; |
| 71 | +} |
| 72 | + |
29 | 73 | export class RPCSecurityError extends RPCError {
|
| 74 | + /** @const */ |
30 | 75 | rpcErrorMessage = 'During the processing of method a security issue occurred preventing receiver from completing the method successfully';
|
| 76 | + /** @const */ |
31 | 77 | rpcErrorCode = 'SecurityError';
|
32 |
| -}; |
| 78 | +} |
| 79 | + |
33 | 80 | export class RPCFormatViolationError extends RPCError {
|
| 81 | + /** @const */ |
34 | 82 | rpcErrorMessage = 'Payload for the method is syntactically incorrect or not conform the PDU structure for the method';
|
| 83 | + /** @const */ |
35 | 84 | rpcErrorCode = 'FormatViolation';
|
36 |
| -}; |
| 85 | +} |
| 86 | + |
37 | 87 | export class RPCFormationViolationError extends RPCError {
|
| 88 | + /** @const */ |
38 | 89 | rpcErrorMessage = 'Payload for the method is syntactically incorrect or not conform the PDU structure for the method';
|
| 90 | + /** @const */ |
39 | 91 | rpcErrorCode = 'FormationViolation';
|
40 |
| -}; |
| 92 | +} |
| 93 | + |
41 | 94 | export class RPCPropertyConstraintViolationError extends RPCError {
|
| 95 | + /** @const */ |
42 | 96 | rpcErrorMessage = 'Payload is syntactically correct but at least one field contains an invalid value';
|
| 97 | + /** @const */ |
43 | 98 | rpcErrorCode = 'PropertyConstraintViolation';
|
44 |
| -}; |
| 99 | +} |
| 100 | + |
45 | 101 | export class RPCOccurenceConstraintViolationError extends RPCError {
|
| 102 | + /** @const */ |
46 | 103 | rpcErrorMessage = 'Payload for the method is syntactically correct but at least one of the fields violates occurence constraints';
|
| 104 | + /** @const */ |
47 | 105 | rpcErrorCode = 'OccurenceConstraintViolation';
|
48 |
| -}; |
| 106 | +} |
| 107 | + |
49 | 108 | export class RPCOccurrenceConstraintViolationError extends RPCError {
|
| 109 | + /** @const */ |
50 | 110 | rpcErrorMessage = 'Payload for the method is syntactically correct but at least one of the fields violates occurence constraints';
|
| 111 | + /** @const */ |
51 | 112 | rpcErrorCode = 'OccurrenceConstraintViolation';
|
52 |
| -}; |
| 113 | +} |
| 114 | + |
53 | 115 | export class RPCTypeConstraintViolationError extends RPCError {
|
| 116 | + /** @const */ |
54 | 117 | rpcErrorMessage = 'Payload for the method is syntactically correct but at least one of the fields violates data type constraints';
|
| 118 | + /** @const */ |
55 | 119 | rpcErrorCode = 'TypeConstraintViolation';
|
56 |
| -}; |
| 120 | +} |
| 121 | + |
57 | 122 | export class RPCMessageTypeNotSupportedError extends RPCError {
|
| 123 | + /** @const */ |
58 | 124 | rpcErrorMessage = 'A message with a Message Type Number received is not supported by this implementation.';
|
| 125 | + /** @const */ |
59 | 126 | rpcErrorCode = 'MessageTypeNotSupported';
|
60 |
| -}; |
| 127 | +} |
| 128 | + |
61 | 129 | export class RPCFrameworkError extends RPCError {
|
| 130 | + /** @const */ |
62 | 131 | rpcErrorMessage = 'Content of the call is not a valid RPC Request, for example: MessageId could not be read.';
|
| 132 | + /** @const */ |
63 | 133 | rpcErrorCode = 'RpcFrameworkError';
|
64 |
| -}; |
| 134 | +} |
65 | 135 |
|
66 | 136 | export class WebsocketUpgradeError extends Error {
|
| 137 | + /** |
| 138 | + * |
| 139 | + * @param {number} code |
| 140 | + * @param {string} [message] |
| 141 | + */ |
67 | 142 | constructor(code, message) {
|
68 | 143 | super(message);
|
| 144 | + |
| 145 | + /** @type {number} */ |
69 | 146 | this.code = code;
|
70 | 147 | }
|
71 | 148 | }
|
0 commit comments