diff --git a/src/authchecker.ts b/src/authchecker.ts index 9b62dfa..f32ec75 100644 --- a/src/authchecker.ts +++ b/src/authchecker.ts @@ -1,5 +1,6 @@ import * as jwt from "jsonwebtoken"; -import { Action, HttpError } from "routing-controllers"; +import { Action } from "routing-controllers"; +import { IllegalJWTError, NoPermissionError } from './errors/AuthError'; // ----------- const sampletoken = jwt.sign({ "permissions": { @@ -22,7 +23,7 @@ const authchecker = async (action: Action, permissions: string | string[]) => { try { jwtPayload = jwt.verify(provided_token, process.env.JWT_SECRET || "secretjwtsecret"); } catch (error) { - throw new HttpError(401, "jwt_illegal") + throw new IllegalJWTError() } if (jwtPayload.permissions) { action.response.local = {} @@ -34,11 +35,11 @@ const authchecker = async (action: Action, permissions: string | string[]) => { if (actual_accesslevel_for_permission.includes(permission_access_level)) { return true; } else { - throw new HttpError(403, "no") + throw new NoPermissionError() } }); } else { - throw new HttpError(403, "no") + throw new NoPermissionError() } // try {