MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / onError

Function onError

apps/web/server/middlewares/error.ts:4–24  ·  view source on GitHub ↗
(error: any, req: any, res: any, _: any)

Source from the content-addressed store, hash-verified

2import { expireSessionCookies } from '@linen/auth-server/server';
3
4export function onError(error: any, req: any, res: any, _: any) {
5 if (error.message === 'jwt expired') {
6 try {
7 expireSessionCookies({ req, res });
8 } catch (error) {}
9 }
10
11 error.status = error instanceof ZodError ? 400 : error.status || 500;
12
13 const path = !!req.baseUrl ? req.baseUrl + req.path : req.url;
14
15 console.error(
16 `[${req.method}] ${path} >> StatusCode:: ${error.status}, Message:: ${error.message}`
17 );
18
19 if (error.status === 500) {
20 error.message = 'Something went wrong';
21 }
22
23 res.status(error.status).json({ message: error.message });
24}
25
26export function onGetError(error: any, req: any, res: any, _: any) {
27 const path = !!req.baseUrl ? req.baseUrl : req.url;

Callers

nothing calls this directly

Calls 2

expireSessionCookiesFunction · 0.90
errorMethod · 0.65

Tested by

no test coverage detected