elysia
elysia copied to clipboard
onError handler isn't getting called during INVALID_COOKIE_SIGNATURE
What version of Elysia.JS is running?
1.0.26
What platform is your computer?
Microsoft Windows NT 10.0.22631.0 x64
What steps can reproduce the bug?
.onError(({ code, set, cookie: { accessToken, refreshToken } }) => {
if (code === "NOT_FOUND")
return { error: "Route not found :(", status: STATUS.ERROR };
if (code === "INVALID_COOKIE_SIGNATURE")
return { error: "Your cookies has been altered", status: STATUS.ERROR };
set.status = 500;
return { error: "Internal Server Error", status: STATUS.ERROR };
})
What is the expected behavior?
When cookies have been altered, it should respond with the format { error: "...", status: "ERROR" }
What do you see instead?
I am just getting raw text when cookies have been altered. onError is not getting called.
Additional information
No response
I am not sure if it's related but when I have separate UI and backend, CORS error is occuring if cookies are altered.
Same issue here for WSL, on elysia 1.1.13.
Also, it seems it works fine on aot: false case
Minimal reproduction example:
import Elysia from 'elysia';
export const app = new Elysia({
cookie: { secrets: 'secret', sign: ['session'] },
})
.onError(({ error }) => {
console.log(error);
return {};
})
.get('', ({ cookie: { session } }) => {
console.log(session);
})
.listen(3000);
console.log('listening on port 3000');
Other errors prints the error and return {} as response
But when try sending request with cookie session=1234, error is not caught at all
Yeah, same issue but it happens for me with code==="VALIDATION" Also @nxht, doing aot:false worked for me too.
Closing as https://github.com/elysiajs/elysia/pull/839#issuecomment-2661407310