alepha
Version:
Easy-to-use modern TypeScript framework for building many kind of applications.
29 lines (25 loc) • 636 B
text/typescript
import { TypeBoxError } from "alepha";
import { HttpError } from "./HttpError.ts";
export class ValidationError extends HttpError {
constructor(message = "Validation has failed", cause?: unknown) {
let fullMessage = message;
let details: string | undefined;
if (cause instanceof TypeBoxError) {
const path = cause.cause.instancePath;
fullMessage = `${message}: ${cause.cause.message}${
path ? ` (${path})` : ""
}`;
if (path) {
details = path;
}
}
super(
{
message: fullMessage,
status: 400,
details,
},
cause,
);
}
}