UNPKG

nestjs-typebox

Version:

This library provides helper utilities for writing and validating NestJS APIs using [TypeBox](https://github.com/sinclairzx81/typebox) as an alternative to class-validator/class-transformer. Can be configured to patch @nestjs/swagger allowing OpenAPI gene

27 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TypeboxValidationException = void 0; const common_1 = require("@nestjs/common"); const errors_1 = require("@sinclair/typebox/errors"); class TypeboxValidationException extends common_1.BadRequestException { constructor(type, errors) { const topLevelErrors = []; const unionPaths = []; for (const error of errors) { // don't deeply traverse union errors to reduce error noise if (unionPaths.some(path => error.path.includes(path))) continue; if (error.type === errors_1.ValueErrorType.Union) { unionPaths.push(error.path); } topLevelErrors.push(error); } super({ statusCode: common_1.HttpStatus.BAD_REQUEST, message: `Validation failed (${type})`, errors: topLevelErrors, }); } } exports.TypeboxValidationException = TypeboxValidationException; //# sourceMappingURL=exceptions.js.map