UNPKG

@russ-b/nestjs-common-tools

Version:
24 lines 975 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createZodValidationErrorResponse = createZodValidationErrorResponse; const common_1 = require("@nestjs/common"); const errors_1 = require("../../errors"); const DEFAULT_VALIDATION_ERROR_MESSAGE = 'Validation failed'; function createZodValidationErrorResponse(exception, options = {}) { return (0, errors_1.createApiErrorResponse)({ statusCode: common_1.HttpStatus.BAD_REQUEST, message: options.message ?? DEFAULT_VALIDATION_ERROR_MESSAGE, code: errors_1.ApiErrorCode.VALIDATION_FAILED, errors: exception.issues.map((issue) => ({ field: formatZodIssuePath(issue.path), message: issue.message, })), }); } function formatZodIssuePath(path) { if (path.length === 0) { return errors_1.API_ERROR_ROOT_FIELD; } return path.map(String).join('.'); } //# sourceMappingURL=zod-validation-error-response.js.map