feat(server): make permission a standalone module (#7880)

This commit is contained in:
forehalo
2024-08-15 10:01:52 +00:00
parent ba8958f39b
commit 624f3514fc
30 changed files with 123 additions and 116 deletions
@@ -198,6 +198,10 @@ export const USER_FRIENDLY_ERRORS = {
type: 'too_many_requests',
message: 'Too many requests.',
},
not_found: {
type: 'resource_not_found',
message: 'Resource not found.',
},
// User Errors
user_not_found: {
@@ -16,6 +16,12 @@ export class TooManyRequest extends UserFriendlyError {
}
}
export class NotFound extends UserFriendlyError {
constructor(message?: string) {
super('resource_not_found', 'not_found', message);
}
}
export class UserNotFound extends UserFriendlyError {
constructor(message?: string) {
super('resource_not_found', 'user_not_found', message);
@@ -508,6 +514,7 @@ export class CannotDeleteOwnAccount extends UserFriendlyError {
export enum ErrorNames {
INTERNAL_SERVER_ERROR,
TOO_MANY_REQUEST,
NOT_FOUND,
USER_NOT_FOUND,
USER_AVATAR_NOT_FOUND,
EMAIL_ALREADY_USED,
@@ -40,5 +40,3 @@ export class ErrorModule implements OnModuleInit {
export { UserFriendlyError } from './def';
export * from './errors.gen';
export * from './payment-required';
export * from './too-many-requests';
@@ -1,10 +0,0 @@
import { HttpException, HttpStatus } from '@nestjs/common';
export class PaymentRequiredException extends HttpException {
constructor(desc?: string, code: string = 'Payment Required') {
super(
HttpException.createBody(desc ?? code, code, HttpStatus.PAYMENT_REQUIRED),
HttpStatus.PAYMENT_REQUIRED
);
}
}
@@ -1,14 +0,0 @@
import { HttpException, HttpStatus } from '@nestjs/common';
export class TooManyRequestsException extends HttpException {
constructor(desc?: string, code: string = 'Too Many Requests') {
super(
HttpException.createBody(
desc ?? code,
code,
HttpStatus.TOO_MANY_REQUESTS
),
HttpStatus.TOO_MANY_REQUESTS
);
}
}