mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 13:47:15 +01:00
Improved error handling for useSession middleware.
This commit is contained in:
parent
8666965930
commit
c5bffb97cc
2 changed files with 13 additions and 8 deletions
|
|
@ -20,14 +20,19 @@ export const useCors = createMiddleware(
|
|||
);
|
||||
|
||||
export const useSession = createMiddleware(async (req, res, next) => {
|
||||
const session = await findSession(req as NextApiRequestCollect);
|
||||
try {
|
||||
const session = await findSession(req as NextApiRequestCollect);
|
||||
|
||||
if (!session) {
|
||||
log('useSession: Session not found');
|
||||
return badRequest(res, 'Session not found.');
|
||||
if (!session) {
|
||||
log('useSession: Session not found');
|
||||
return badRequest(res, 'Session not found.');
|
||||
}
|
||||
|
||||
(req as any).session = session;
|
||||
} catch (e: any) {
|
||||
return badRequest(res, e.message);
|
||||
}
|
||||
|
||||
(req as any).session = session;
|
||||
next();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue