Skip to content

Commit ccb3088

Browse files
committed
refactor(val): readBoundedJson returns T|undefined (not T|null)
1 parent 31b9eb3 commit ccb3088

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

val/util.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@ export const getIp = (c: Context): string =>
3434

3535
// Read a JSON body with a hard byte cap. A client can't DOS us by
3636
// streaming an enormous request — anything over `maxBytes` returns
37-
// null and the caller emits 400. Returns null on parse errors too so
38-
// call sites only check for one failure mode.
37+
// undefined and the caller emits 400. Parse errors return undefined
38+
// too so call sites only check for one failure mode. Using undefined
39+
// (not null) keeps the absent-value signal consistent with TS defaults
40+
// (optional fields, early returns, etc.).
3941
export const readBoundedJson = async <T>(
4042
c: Context,
4143
maxBytes: number,
42-
): Promise<T | null> => {
44+
): Promise<T | undefined> => {
4345
try {
4446
const text = await c.req.text()
4547
if (text.length > maxBytes) {
46-
return null
48+
return undefined
4749
}
4850
return JSON.parse(text) as T
4951
} catch {
50-
return null
52+
return undefined
5153
}
5254
}
5355

0 commit comments

Comments
 (0)