File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.).
3941export 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
You can’t perform that action at this time.
0 commit comments