From ed632379834ede38f76ae1a8303d8689d5689c48 Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Tue, 10 Dec 2024 11:52:03 -0500 Subject: [PATCH] Raise 404, not 500, if circularId is not finite Fixes the following error: ``` 2024-12-10T16:45:51.373Z 96341ef3-33ab-481f-9a5a-9d7c10f78c14 ERROR Error: Special numeric value NaN is not allowed at convertToNumberAttr (/var/runtime/node_modules/@aws-sdk/util-dynamodb/dist-cjs/index.js:212:11) at convertToAttr (/var/runtime/node_modules/@aws-sdk/util-dynamodb/dist-cjs/index.js:120:12) at marshall (/var/runtime/node_modules/@aws-sdk/util-dynamodb/dist-cjs/index.js:307:26) at marshallFunc (/var/runtime/node_modules/@aws-sdk/lib-dynamodb/dist-cjs/index.js:130:97) at processObj (/var/runtime/node_modules/@aws-sdk/lib-dynamodb/dist-cjs/index.js:69:14) at /var/runtime/node_modules/@aws-sdk/lib-dynamodb/dist-cjs/index.js:122:28 at Array.reduce () at processAllKeysInObj (/var/runtime/node_modules/@aws-sdk/lib-dynamodb/dist-cjs/index.js:118:30) at processObj (/var/runtime/node_modules/@aws-sdk/lib-dynamodb/dist-cjs/index.js:78:16) at processKeysInObj (/var/runtime/node_modules/@aws-sdk/lib-dynamodb/dist-cjs/index.js:107:28) ``` --- app/routes/circulars/circulars.server.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/routes/circulars/circulars.server.ts b/app/routes/circulars/circulars.server.ts index 89e3ffa80..9dc3292ea 100644 --- a/app/routes/circulars/circulars.server.ts +++ b/app/routes/circulars/circulars.server.ts @@ -240,6 +240,8 @@ export async function get( circularId: number, version?: number ): Promise { + if (isNaN(circularId) || (version !== undefined && isNaN(version))) + throw new Response(null, { status: 404 }) const circularVersions = await getDynamoDBVersionAutoIncrement(circularId) const result = await circularVersions.get(version) if (!result) @@ -367,6 +369,7 @@ export async function putVersion( * @returns an array of previous versions of a Circular sorted by version */ export async function getVersions(circularId: number): Promise { + if (isNaN(circularId)) throw new Response(null, { status: 404 }) const circularVersionsAutoIncrement = await getDynamoDBVersionAutoIncrement(circularId) return await circularVersionsAutoIncrement.list()