improve error handling

This commit is contained in:
Julian Krauser 2024-08-23 09:44:36 +02:00
parent e1ec65350d
commit bcfba8b448
5 changed files with 22 additions and 20 deletions

View file

@ -6,10 +6,10 @@ import InternalException from "../exceptions/internalException";
import { JWTHelper } from "../helpers/jwtHelper";
export default async function authenticate(req: Request, res: Response, next: Function) {
const bearer = req.headers.authorization;
const bearer = req.headers.authorization?.split(" ")?.[1] ?? undefined;
if (!bearer) {
throw new BadRequestException("Provide Authorization Header");
throw new BadRequestException("Provide valid Authorization Header");
}
let decoded: string | jwt.JwtPayload;