feat(validation): ValidationError → 422 with source + issues (before HttpError)
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
3 files changed
+40
-3
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import type { StandardIssue } from './standard-schema';
|
||||
|
||||
export class HttpError extends Error {
|
||||
constructor(readonly status: number, message?: string, readonly body?: unknown) {
|
||||
super(message ?? `HTTP ${status}`);
|
||||
@@ -21,6 +23,12 @@ export class Redirect extends HttpError {
|
||||
constructor(readonly location: string) { super(302); }
|
||||
}
|
||||
|
||||
export class ValidationError extends HttpError {
|
||||
constructor(public issues: StandardIssue[], public source: string) {
|
||||
super(422, 'Validation failed');
|
||||
}
|
||||
}
|
||||
|
||||
export function isHttpError(e: unknown): e is HttpError {
|
||||
return e instanceof HttpError;
|
||||
}
|
||||
Reference in new issue
Block a user