mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
53354224fc
Upgrades biome to 1.6.1, and updates husky pre-commit hook. Most changes here are making type imports explicit.
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { type ApiErrorSchema, UnleashError } from './unleash-error';
|
|
|
|
type Permission = string | string[];
|
|
|
|
class PermissionError extends UnleashError {
|
|
statusCode = 403;
|
|
|
|
permissions: Permission;
|
|
|
|
constructor(permission: Permission = [], environment?: string) {
|
|
const permissions = Array.isArray(permission)
|
|
? permission
|
|
: [permission];
|
|
|
|
const permissionsMessage =
|
|
permissions.length === 1
|
|
? `the "${permissions[0]}" permission`
|
|
: `one of the following permissions: ${permissions
|
|
.map((perm) => `"${perm}"`)
|
|
.join(', ')}`;
|
|
|
|
const message = `You don't have the required permissions to perform this operation. To perform this action, you need ${permissionsMessage}${
|
|
environment ? ` in the "${environment}" environment.` : `.`
|
|
}`;
|
|
|
|
super(message);
|
|
|
|
this.permissions = permissions;
|
|
}
|
|
|
|
toJSON(): ApiErrorSchema {
|
|
return {
|
|
...super.toJSON(),
|
|
permissions: this.permissions,
|
|
};
|
|
}
|
|
}
|
|
|
|
export default PermissionError;
|
|
module.exports = PermissionError;
|