From f251b7acdbc8e277971cf97cfe619f441ac0362a Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Fri, 4 Dec 2020 22:18:54 +0100 Subject: [PATCH] authchecker - use new custom Errors ref #12 --- src/authchecker.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 {