You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.7 KiB
39 lines
1.7 KiB
import { CodeError, errCode, type ErrCode, type ErrorMessages } from '$libs/errs';
|
|
import { PERM_ERR } from '$libs/perm/errors';
|
|
|
|
// ── Error codes ────────────────────────────────────────────────────────
|
|
|
|
export const PERM_ERR_INVALID_BODY: ErrCode = errCode(PERM_ERR, 'invalid_body');
|
|
export const PERM_ERR_SERVER_DISPOSED: ErrCode = errCode(PERM_ERR, 'server_disposed');
|
|
|
|
// ── Error messages ─────────────────────────────────────────────────────
|
|
|
|
export const PERM_SERVER_ERROR_MESSAGES: ErrorMessages = {
|
|
[PERM_ERR_INVALID_BODY]: 'Request body must be an object.',
|
|
[PERM_ERR_SERVER_DISPOSED]: 'Permission engine disposed.'
|
|
};
|
|
|
|
// ── Error classes ──────────────────────────────────────────────────────
|
|
|
|
export class PermInvalidBodyError extends CodeError {
|
|
constructor(message: string) {
|
|
super(PERM_ERR_INVALID_BODY, { message });
|
|
}
|
|
}
|
|
|
|
export class PermDisposedError extends CodeError {
|
|
constructor(message: string) {
|
|
super(PERM_ERR_SERVER_DISPOSED, { message });
|
|
}
|
|
}
|
|
|
|
// ── Type guards ────────────────────────────────────────────────────────
|
|
|
|
export function isPermInvalidBodyError(error: unknown): error is PermInvalidBodyError {
|
|
return error instanceof PermInvalidBodyError;
|
|
}
|
|
|
|
export function isPermDisposedError(error: unknown): error is PermDisposedError {
|
|
return error instanceof PermDisposedError;
|
|
}
|