Skip to content

Commit c4dac63

Browse files
fix: ws errors should conform to jsonrpc spec (#2505)
* fix: ws errors should conform to jsonrpc spec Signed-off-by: Ted Yeh <[email protected]> * Update packages/ws-server/src/metrics/connectionLimiter.ts Co-authored-by: Logan Nguyen <[email protected]> Signed-off-by: ted-yeh-vc <[email protected]> * Update packages/ws-server/src/metrics/connectionLimiter.ts Co-authored-by: Logan Nguyen <[email protected]> Signed-off-by: ted-yeh-vc <[email protected]> * Update packages/ws-server/src/metrics/connectionLimiter.ts Co-authored-by: Logan Nguyen <[email protected]> Signed-off-by: ted-yeh-vc <[email protected]> --------- Signed-off-by: Ted Yeh <[email protected]> Signed-off-by: ted-yeh-vc <[email protected]> Co-authored-by: Logan Nguyen <[email protected]>
1 parent c6cfd6c commit c4dac63

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

packages/ws-server/src/metrics/connectionLimiter.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ export default class ConnectionLimiter {
133133
ctx.websocket.send(
134134
JSON.stringify({
135135
jsonrpc: '2.0',
136-
error: `Closing current connection due to exceeded maximum connections (max_con=${MAX_CONNECTION_LIMIT})`,
136+
error: {
137+
code: CONNECTION_LIMIT_EXCEEDED.code,
138+
message: CONNECTION_LIMIT_EXCEEDED.message,
139+
data: {
140+
message: CONNECTION_LIMIT_EXCEEDED.message,
141+
max_connection: MAX_CONNECTION_LIMIT,
142+
},
143+
},
137144
id: '1',
138145
}),
139146
);
@@ -152,7 +159,14 @@ export default class ConnectionLimiter {
152159
ctx.websocket.send(
153160
JSON.stringify({
154161
jsonrpc: '2.0',
155-
error: `Closing current connection due to exceeded maximum connections from a single IP: address ${ip} - ${this.clientIps[ip]} connections. (max_con=${MAX_CONNECTION_LIMIT_PER_IP})`,
162+
error: {
163+
code: CONNECTION_IP_LIMIT_EXCEEDED.code,
164+
message: CONNECTION_IP_LIMIT_EXCEEDED.message,
165+
data: {
166+
message: CONNECTION_IP_LIMIT_EXCEEDED.message,
167+
max_connection: MAX_CONNECTION_LIMIT_PER_IP,
168+
},
169+
},
156170
id: '1',
157171
}),
158172
);
@@ -188,7 +202,14 @@ export default class ConnectionLimiter {
188202
websocket.send(
189203
JSON.stringify({
190204
jsonrpc: '2.0',
191-
error: `Closing current connection due to reaching TTL (${maxInactivityTTL}ms)`,
205+
error: {
206+
code: TTL_EXPIRED.code,
207+
message: TTL_EXPIRED.message,
208+
data: {
209+
message: TTL_EXPIRED.message,
210+
max_inactivity_TTL: maxInactivityTTL,
211+
},
212+
},
192213
id: '1',
193214
}),
194215
);

0 commit comments

Comments
 (0)