Skip to content

Commit 57d1290

Browse files
committed
feat: too big res usage (#4630)
Signed-off-by: Mariusz Jasuwienas <[email protected]>
1 parent fec864c commit 57d1290

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/server/src/compliance.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const INVALID_METHOD_RESPONSE_BODY = {
2929
const makeSureBodyExistsAndCanBeChecked = (ctx: IResponseContext) => {
3030
if (!ctx.body) {
3131
ctx.status = 400;
32-
ctx.body = FALLBACK_RESPONSE_BODY;
32+
ctx.body = { ...FALLBACK_RESPONSE_BODY };
3333
return false;
3434
}
3535

@@ -40,11 +40,11 @@ const makeSureBodyExistsAndCanBeChecked = (ctx: IResponseContext) => {
4040

4141
if (typeof ctx.body !== 'object') {
4242
ctx.status = 400;
43-
ctx.body = FALLBACK_RESPONSE_BODY;
43+
ctx.body = { ...FALLBACK_RESPONSE_BODY };
4444
return false;
4545
}
46-
ctx.body.jsonrpc ||= FALLBACK_RESPONSE_BODY.jsonrpc;
47-
ctx.body.id ||= FALLBACK_RESPONSE_BODY.id;
46+
if (!ctx.body.jsonrpc) ctx.body.jsonrpc = FALLBACK_RESPONSE_BODY.jsonrpc;
47+
if (!ctx.body.id) ctx.body.id = FALLBACK_RESPONSE_BODY.id;
4848

4949
return true;
5050
};
@@ -59,7 +59,7 @@ const makeSureBodyExistsAndCanBeChecked = (ctx: IResponseContext) => {
5959
export const jsonRpcComplianceLayer = (ctx: IResponseContext & ParameterizedContext) => {
6060
if (!makeSureBodyExistsAndCanBeChecked(ctx)) return;
6161
if (ctx.status === 400) {
62-
if (!ctx.body.error || !ctx.body.error.code) ctx.body.error = FALLBACK_RESPONSE_BODY.error;
62+
if (!ctx.body.error?.code) ctx.body.error = FALLBACK_RESPONSE_BODY.error;
6363
if (VALID_JSON_RPC_HTTP_REQUESTS_STATUS_CODE) ctx.status = 200;
6464
}
6565
};

0 commit comments

Comments
 (0)