error permission

This commit is contained in:
kittapath 2024-08-20 13:55:59 +07:00
parent bd1f889fba
commit a2e3c79a7c

View file

@ -1,16 +1,3 @@
import {
Controller,
Request,
Get,
Post,
Put,
Delete,
Patch,
Route,
Security,
Tags,
Path,
} from "tsoa";
import axios from "axios"; import axios from "axios";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import CallAPI from "./call-api"; import CallAPI from "./call-api";
@ -42,7 +29,11 @@ class CheckAuth {
return role.attrPrivilege; return role.attrPrivilege;
}) })
.catch((x) => { .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) { public async PermissionOrg(req: RequestWithUser, system: string, action: string) {
@ -123,7 +114,11 @@ class CheckAuth {
return data; return data;
}) })
.catch((x) => { .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( public async PermissionOrgByUser(
@ -174,8 +169,8 @@ class CheckAuth {
return true; return true;
}) })
.catch((x) => { .catch((x) => {
if (x.status == 403) { if (x.status != undefined) {
throw new HttpError(HttpStatus.FORBIDDEN, x.message); throw new HttpError(x.status, x.message);
} else { } else {
throw new HttpError(HttpStatus.FORBIDDEN, x); throw new HttpError(HttpStatus.FORBIDDEN, x);
} }