@openaddresses/batch-schema 10.21.0 → 10.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,10 @@
10
10
 
11
11
  ## Version History
12
12
 
13
+ ### v10.22.0
14
+
15
+ - :rocket: Increase usefulness of schema error messages by including the schema path and the value that failed validation
16
+
13
17
  ### v10.21.0
14
18
 
15
19
  - :rocket: Surface outgoing schema errors in the logs
package/lib/schema.ts CHANGED
@@ -159,7 +159,11 @@ export default class Schemas {
159
159
  const errors: Array<ErrorListItem> = [];
160
160
  if (paramsValidation && !paramsValidation(req.params)) errors.push({ type: 'Params', errors: paramsValidation.errors as ErrorObject[] });
161
161
  if (queryValidation && !queryValidation(req.query)) errors.push({ type: 'Query', errors: queryValidation.errors as ErrorObject[] });
162
- if (errors.length) return Err.respond(new Err(400, null, 'Validation Error'), res, errors);
162
+ if (errors.length) {
163
+ return Err.respond(new Err(
164
+ 400, null, `Validation Error GET ${path}`
165
+ ), res, errors);
166
+ }
163
167
 
164
168
  const json = res.json;
165
169
  res.json = function(obj) {
@@ -207,7 +211,11 @@ export default class Schemas {
207
211
  const errors: Array<ErrorListItem> = [];
208
212
  if (paramsValidation && !paramsValidation(req.params)) errors.push({ type: 'Params', errors: paramsValidation.errors as ErrorObject[] });
209
213
  if (queryValidation && !queryValidation(req.query)) errors.push({ type: 'Query', errors: queryValidation.errors as ErrorObject[] });
210
- if (errors.length) return Err.respond(new Err(400, null, 'Validation Error'), res, errors);
214
+ if (errors.length) {
215
+ return Err.respond(new Err(
216
+ 400, null, `Validation Error DELETE ${path}`
217
+ ), res, errors);
218
+ }
211
219
 
212
220
  const json = res.json;
213
221
  res.json = function(obj) {
@@ -256,7 +264,11 @@ export default class Schemas {
256
264
  if (paramsValidation && !paramsValidation(req.params)) errors.push({ type: 'Params', errors: paramsValidation.errors as ErrorObject[] });
257
265
  if (queryValidation && !queryValidation(req.query)) errors.push({ type: 'Query', errors: queryValidation.errors as ErrorObject[] });
258
266
  if (bodyValidation && !bodyValidation(req.body)) errors.push({ type: 'Body', errors: bodyValidation.errors as ErrorObject[] });
259
- if (errors.length) return Err.respond(new Err(400, null, 'Validation Error'), res, errors);
267
+ if (errors.length) {
268
+ return Err.respond(new Err(
269
+ 400, null, `Validation Error POST ${path}`
270
+ ), res, errors);
271
+ }
260
272
 
261
273
  const json = res.json;
262
274
  res.json = function(obj) {
@@ -305,7 +317,11 @@ export default class Schemas {
305
317
  if (paramsValidation && !paramsValidation(req.params)) errors.push({ type: 'Params', errors: paramsValidation.errors as ErrorObject[] });
306
318
  if (queryValidation && !queryValidation(req.query)) errors.push({ type: 'Query', errors: queryValidation.errors as ErrorObject[] });
307
319
  if (bodyValidation && !bodyValidation(req.body)) errors.push({ type: 'Body', errors: bodyValidation.errors as ErrorObject[] });
308
- if (errors.length) return Err.respond(new Err(400, null, 'Validation Error'), res, errors);
320
+ if (errors.length) {
321
+ return Err.respond(new Err(
322
+ 400, null, `Validation Error PATCH ${path}`
323
+ ), res, errors);
324
+ }
309
325
 
310
326
  const json = res.json;
311
327
  res.json = function(obj) {
@@ -354,7 +370,11 @@ export default class Schemas {
354
370
  if (paramsValidation && !paramsValidation(req.params)) errors.push({ type: 'Params', errors: paramsValidation.errors as ErrorObject[] });
355
371
  if (queryValidation && !queryValidation(req.query)) errors.push({ type: 'Query', errors: queryValidation.errors as ErrorObject[] });
356
372
  if (bodyValidation && !bodyValidation(req.body)) errors.push({ type: 'Body', errors: bodyValidation.errors as ErrorObject[] });
357
- if (errors.length) return Err.respond(new Err(400, null, 'Validation Error'), res, errors);
373
+ if (errors.length) {
374
+ return Err.respond(new Err(
375
+ 400, null, `Validation Error PUT ${path}`
376
+ ), res, errors);
377
+ }
358
378
 
359
379
  const json = res.json;
360
380
  res.json = function(obj) {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "root": true,
5
5
  "main": "dist/index.js",
6
6
  "types": "index.ts",
7
- "version": "10.21.0",
7
+ "version": "10.22.0",
8
8
  "description": "Strongly Validated JSON Schema support for address",
9
9
  "repository": "git@github.com:openaddresses/batch-schema",
10
10
  "author": "ingalls <nick@ingalls.ca>",
@@ -48,7 +48,7 @@ test('GET: api/schema?method=FAKE', async (t) => {
48
48
 
49
49
  t.deepEquals(await res.json(), {
50
50
  status: 400,
51
- message: 'Validation Error',
51
+ message: 'Validation Error GET /schema',
52
52
  messages: [
53
53
  {"type":"Query","errors":[{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/0/const","keyword":"const","params":{"allowedValue":"GET"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/1/const","keyword":"const","params":{"allowedValue":"PUT"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/2/const","keyword":"const","params":{"allowedValue":"POST"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/3/const","keyword":"const","params":{"allowedValue":"DELETE"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/4/const","keyword":"const","params":{"allowedValue":"OPTIONS"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/5/const","keyword":"const","params":{"allowedValue":"HEAD"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/6/const","keyword":"const","params":{"allowedValue":"PATCH"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/7/const","keyword":"const","params":{"allowedValue":"TRACE"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf","keyword":"anyOf","params":{},"message":"must match a schema in anyOf"}]}
54
54
  ]