mongoose-zod-error-formatter
Version:
A powerful error formatter utility for Mongoose and Zod validation errors, designed for Express.js applications. Simplify and unify your API error handling with structured, user-friendly error messages.
19 lines (18 loc) • 591 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatValidationError = void 0;
const formatValidationError = (error) => {
const errors = Object.values(error.errors).map((el) => {
return {
path: el === null || el === void 0 ? void 0 : el.path,
message: el === null || el === void 0 ? void 0 : el.message,
};
});
const statusCode = 400;
return {
statusCode,
message: "Validation Error",
errorMessages: errors,
};
};
exports.formatValidationError = formatValidationError;