mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-02 08:06:00 +00:00
ca55503e66
* refactored core and core/utils imports * refactored core and core/utils imports * refactored media imports * refactored auth imports * refactored data imports * updated package json exports, fixed mm config * fix tests
68 lines
1.5 KiB
TypeScript
68 lines
1.5 KiB
TypeScript
import { Exception } from "core/errors";
|
|
import { isDebug } from "core/env";
|
|
import { HttpStatus } from "bknd/utils";
|
|
|
|
export class AuthException extends Exception {
|
|
getSafeErrorAndCode() {
|
|
return {
|
|
error: "Invalid credentials",
|
|
code: HttpStatus.UNAUTHORIZED,
|
|
};
|
|
}
|
|
|
|
override toJSON(): any {
|
|
if (isDebug()) {
|
|
return super.toJSON();
|
|
}
|
|
|
|
return {
|
|
error: this.getSafeErrorAndCode().error,
|
|
type: "AuthException",
|
|
};
|
|
}
|
|
}
|
|
|
|
export class UserExistsException extends AuthException {
|
|
override name = "UserExistsException";
|
|
override code = HttpStatus.UNPROCESSABLE_ENTITY;
|
|
|
|
constructor() {
|
|
super("User already exists");
|
|
}
|
|
}
|
|
|
|
export class UserNotFoundException extends AuthException {
|
|
override name = "UserNotFoundException";
|
|
override code = HttpStatus.NOT_FOUND;
|
|
|
|
constructor() {
|
|
super("User not found");
|
|
}
|
|
}
|
|
|
|
export class InvalidCredentialsException extends AuthException {
|
|
override name = "InvalidCredentialsException";
|
|
override code = HttpStatus.UNAUTHORIZED;
|
|
|
|
constructor() {
|
|
super("Invalid credentials");
|
|
}
|
|
}
|
|
|
|
export class UnableToCreateUserException extends AuthException {
|
|
override name = "UnableToCreateUserException";
|
|
override code = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
|
|
constructor() {
|
|
super("Unable to create user");
|
|
}
|
|
}
|
|
|
|
export class InvalidConditionsException extends AuthException {
|
|
override code = HttpStatus.UNPROCESSABLE_ENTITY;
|
|
|
|
constructor(message: string) {
|
|
super(message ?? "Invalid conditions");
|
|
}
|
|
}
|