mirror of
https://github.com/bubblecup-12/VogelSocialMedia.git
synced 2025-07-10 04:28:50 +00:00
standardised error messages
This commit is contained in:
parent
dee6a19e51
commit
4042b135c4
3 changed files with 30 additions and 16 deletions
|
@ -32,24 +32,25 @@ export function authenticateToken() {
|
|||
else {
|
||||
jwt.verify(token, JWT_SECRET, (err: any, user: any) => {
|
||||
// verify the token with the secret
|
||||
console.log(err);
|
||||
|
||||
if (err) {
|
||||
if (err instanceof TokenExpiredError)
|
||||
if (err instanceof TokenExpiredError) {
|
||||
// check if the error is expired and return 401
|
||||
res
|
||||
.status(401)
|
||||
.json({
|
||||
error: "Token expired",
|
||||
details: [{ message: "Token expired" }],
|
||||
});
|
||||
res.status(401).json({
|
||||
error: "Token expired",
|
||||
details: [{ message: "Token expired" }],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// if the token is invalid, return 403 Forbidden
|
||||
else
|
||||
res
|
||||
.status(403)
|
||||
.json({
|
||||
error: "Invalid token",
|
||||
details: [{ message: "Invalid token" }],
|
||||
});
|
||||
else {
|
||||
res.status(403).json({
|
||||
error: "Invalid token",
|
||||
details: [{ message: "Invalid token" }],
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
|
|
@ -16,10 +16,12 @@ export function validateData(schema: z.ZodObject<any, any>) {
|
|||
res
|
||||
.status(StatusCodes.BAD_REQUEST)
|
||||
.json({ error: "Invalid data", details: errorMessages });
|
||||
return;
|
||||
} else {
|
||||
res
|
||||
.status(StatusCodes.INTERNAL_SERVER_ERROR)
|
||||
.json({ error: "Internal Server Error" });
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue