Files
bknd/app/src/core/errors.ts
T
dswbx 79ca2a9939 add bcrypt and refactored auth resolve (#147)
* reworked auth architecture with improved password handling and claims

Refactored password strategy to prepare supporting bcrypt, improving hashing/encryption flexibility. Updated authentication flow with enhanced user resolution mechanisms, safe JWT generation, and consistent profile handling. Adjusted dependencies to include bcryptjs and updated lock files accordingly.

* fix strategy forms handling, add register route and hidden fields

Refactored strategy forms to include hidden fields for type and name. Added a registration route with necessary adjustments to the admin controller and routes. Corrected field handling within relevant forms and components.

* refactored auth handling to support bcrypt, extracted user pool

* update email regex to allow '+' and '_' characters

* update test stub password for AppAuth spec

* update data exceptions to use HttpStatus constants, adjust logging level in AppUserPool

* rework strategies to extend a base class instead of interface

* added simple bcrypt test
2025-04-20 10:46:29 +02:00

51 lines
1.1 KiB
TypeScript

import type { ContentfulStatusCode } from "hono/utils/http-status";
import { HttpStatus } from "./utils/reqres";
export class Exception extends Error {
code: ContentfulStatusCode = HttpStatus.BAD_REQUEST;
override name = "Exception";
protected _context = undefined;
constructor(message: string, code?: ContentfulStatusCode) {
super(message);
if (code) {
this.code = code;
}
}
context(context: any) {
this._context = context;
return this;
}
toJSON() {
return {
error: this.message,
type: this.name,
context: this._context,
};
}
}
export class BkndError extends Error {
constructor(
message: string,
public details?: Record<string, any>,
public type?: string,
) {
super(message);
}
static with(message: string, details?: Record<string, any>, type?: string) {
throw new BkndError(message, details, type);
}
toJSON() {
return {
type: this.type ?? "unknown",
message: this.message,
details: this.details,
};
}
}