Comparing version 0.7.5 to 0.7.6
@@ -9,2 +9,3 @@ import { Exception } from 'typesafe-exception'; | ||
constructor(schema: Schema<unknown>, errors: DecodeError[]); | ||
protected formatMessage(errors: DecodeError[]): string; | ||
} | ||
@@ -11,0 +12,0 @@ export interface DecodeError { |
@@ -7,8 +7,18 @@ "use strict"; | ||
const store_1 = require("./store"); | ||
const util_1 = require("./util"); | ||
class ValidationError extends typesafe_exception_1.Exception { | ||
constructor(schema, errors) { | ||
var _a; | ||
super(`Validation failed (${(_a = schema.id) !== null && _a !== void 0 ? _a : schema.type}}`, { errors }); | ||
super('ValidationError', { errors }); | ||
this.status = 400; | ||
const type = util_1.capitalize((_a = schema.id) !== null && _a !== void 0 ? _a : schema.type); | ||
const msg = this.formatMessage(errors); | ||
this.message = `${type} validation failed:\n${msg}`; | ||
} | ||
formatMessage(errors) { | ||
return errors.map(e => { | ||
const pointer = e.path.join('.'); | ||
return ` - ${pointer} ${e.path}`; | ||
}).join('\n'); | ||
} | ||
} | ||
@@ -15,0 +25,0 @@ exports.ValidationError = ValidationError; |
export declare type DataType = 'string' | 'boolean' | 'number' | 'object' | 'array' | 'any' | 'null'; | ||
export declare function getType(value: unknown): DataType; | ||
export declare function capitalize(str: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getType = void 0; | ||
exports.capitalize = exports.getType = void 0; | ||
function getType(value) { | ||
@@ -18,1 +18,5 @@ if (value == null) { | ||
exports.getType = getType; | ||
function capitalize(str) { | ||
return str.substring(0, 1).toUpperCase() + str.substring(1); | ||
} | ||
exports.capitalize = capitalize; |
{ | ||
"name": "airtight", | ||
"version": "0.7.5", | ||
"version": "0.7.6", | ||
"description": "Tight subset of JSON schema", | ||
@@ -5,0 +5,0 @@ "main": "out/main/index.js", |
17210
459