From a2e3c79a7c83b9aefcb168b17d6e80a33e379a20 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 20 Aug 2024 13:55:59 +0700 Subject: [PATCH] error permission --- src/interfaces/permission.ts | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 96fd0bd7..65a574c8 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -1,16 +1,3 @@ -import { - Controller, - Request, - Get, - Post, - Put, - Delete, - Patch, - Route, - Security, - Tags, - Path, -} from "tsoa"; import axios from "axios"; import { RequestWithUser } from "../middlewares/user"; import CallAPI from "./call-api"; @@ -42,7 +29,11 @@ class CheckAuth { return role.attrPrivilege; }) .catch((x) => { - throw new HttpError(HttpStatus.FORBIDDEN, x); + if (x.status != undefined) { + throw new HttpError(x.status, x.message); + } else { + throw new HttpError(HttpStatus.FORBIDDEN, x); + } }); } public async PermissionOrg(req: RequestWithUser, system: string, action: string) { @@ -123,7 +114,11 @@ class CheckAuth { return data; }) .catch((x) => { - throw new HttpError(HttpStatus.FORBIDDEN, x); + if (x.status != undefined) { + throw new HttpError(x.status, x.message); + } else { + throw new HttpError(HttpStatus.FORBIDDEN, x); + } }); } public async PermissionOrgByUser( @@ -174,8 +169,8 @@ class CheckAuth { return true; }) .catch((x) => { - if (x.status == 403) { - throw new HttpError(HttpStatus.FORBIDDEN, x.message); + if (x.status != undefined) { + throw new HttpError(x.status, x.message); } else { throw new HttpError(HttpStatus.FORBIDDEN, x); }