You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Linux 6.13.5 x86_64 unknown | NixOS 25.05 (Warbler)
What steps can reproduce the bug?
constapp=newElysia({prefix: "/api"}).onError(({ error, code, set, server, request })=>{// This doesn't work:if(code=="INTERNAL_SERVER_ERROR"||code=="UNKNOWN"||typeofcode=="number"){console.error(`Caught while handling request from ${server?.requestIP(request)}:\n`,error);set.status=500;return{message: "Internal API error"};}})
What is the expected behavior?
code is as its type says, (parameter) code: number | "UNKNOWN" | "VALIDATION" | "NOT_FOUND" | "PARSE" | "INTERNAL_SERVER_ERROR" | "INVALID_COOKIE_SIGNATURE"
What do you see instead?
code can be one of the enums or a stringified number, so I have to attempt to cast it to check: !isNaN(+code))
Additional information
No response
Have you try removing the node_modules and bun.lockb and try again yet?
nope
The text was updated successfully, but these errors were encountered:
It seems very unlikely that the code is a number. It's better to always keep ElysiaJS updated. If you want to send an internal error like this, it's better to do it this way. Here's the code:
.onError(({ code })=>{if(code==='INTERNAL_SERVER_ERROR')return'Internal API error';})
It seems very unlikely that the code is a number. It's better to always keep ElysiaJS updated. If you want to send an internal error like this, it's better to do it this way. Here's the code:
The code can indeed be a number as per src/types.ts:
What version of Elysia is running?
1.2.24(@sinclair/[email protected])([email protected])([email protected])
What platform is your computer?
Linux 6.13.5 x86_64 unknown | NixOS 25.05 (Warbler)
What steps can reproduce the bug?
What is the expected behavior?
code
is as its type says,(parameter) code: number | "UNKNOWN" | "VALIDATION" | "NOT_FOUND" | "PARSE" | "INTERNAL_SERVER_ERROR" | "INVALID_COOKIE_SIGNATURE"
What do you see instead?
code can be one of the enums or a stringified number, so I have to attempt to cast it to check:
!isNaN(+code))
Additional information
No response
Have you try removing the
node_modules
andbun.lockb
and try again yet?nope
The text was updated successfully, but these errors were encountered: