diff --git a/src/middlewares/auth.ts b/src/middlewares/auth.ts index ad0bb1e..5aecde8 100644 --- a/src/middlewares/auth.ts +++ b/src/middlewares/auth.ts @@ -12,6 +12,6 @@ export async function expressAuthentication( case "keycloak": return keycloakAuth(request, scopes); default: - throw new HttpError(HttpStatus.NOT_IMPLEMENTED, "ไม่ทราบวิธียืนยันตัวตน"); + throw new HttpError(HttpStatus.NOT_IMPLEMENTED, "Unknown how to verify identity.", "unknowHowToVerify"); } } diff --git a/src/middlewares/role.ts b/src/middlewares/role.ts index d02d316..dd2ec2f 100644 --- a/src/middlewares/role.ts +++ b/src/middlewares/role.ts @@ -5,14 +5,14 @@ import HttpStatus from "../interfaces/http-status"; export function role( role: string | string[], - errorMessage: string = "คุณไม่มีสิทธิในการเข้าถึงทรัพยากรดังกล่าว", + errorMessage: string = "You do not have permission to access this resource.", ) { return (req: RequestWithUser, _res: Response, next: NextFunction) => { if (!Array.isArray(role) && !req.user.role.includes(role) && !req.user.role.includes("*")) { - throw new HttpError(HttpStatus.FORBIDDEN, errorMessage); + throw new HttpError(HttpStatus.FORBIDDEN, errorMessage, "noPermissionToAccess"); } if (role !== "*" && !req.user.role.some((v) => role.includes(v))) { - throw new HttpError(HttpStatus.FORBIDDEN, errorMessage); + throw new HttpError(HttpStatus.FORBIDDEN, errorMessage, "noPermissionToAccess"); } return next(); };