@openaddresses/batch-schema 2.3.4 → 2.4.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
+ ### v2.4.0
14
+
15
+ - :tada: Add `schema.not_found()`
16
+
13
17
  ### v2.3.4
14
18
 
15
19
  - :arrow_up: Update base deps
package/README.md CHANGED
@@ -43,6 +43,9 @@ async function server() {
43
43
  });
44
44
  });
45
45
 
46
+ // Handle Unmatched Routes
47
+ schema.not_found();
48
+
46
49
  // Handle Validation Errors => JSON Middleware
47
50
  schema.error();
48
51
  }
@@ -72,6 +75,15 @@ Adds a route called `GET /schema` which allows the caller to get a list of endpo
72
75
  as well as full schema details for every route. If your API is public we recommend enabling this feature, however
73
76
  if you do not wish for API routes to be published, this feature is disabled unless called.
74
77
 
78
+ ### schema.not_found
79
+
80
+ Adds a middlware which will catch all routes that have not been defined and return
81
+ a standard error object.
82
+
83
+ ```
84
+ schema.not_found()
85
+ ```
86
+
75
87
  ### schema.error
76
88
 
77
89
  Adds a middlware which will convert validation errors into a standard JSON error format.
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports.Schema = require('./lib/schema');
4
- module.exports.Err = require('./lib/error')
4
+ module.exports.Err = require('./lib/error');
package/lib/schema.js CHANGED
@@ -236,6 +236,19 @@ class Schemas {
236
236
  return schema;
237
237
  }
238
238
 
239
+ /**
240
+ * Catch all for unmatched routes
241
+ */
242
+ not_found() {
243
+ this.router.all('*', (req, res) => {
244
+ return res.status(404).json({
245
+ status: 404,
246
+ message: 'API endpoint does not exist!',
247
+ messages: []
248
+ });
249
+ });
250
+ }
251
+
239
252
  /**
240
253
  * Convert validation errors into standardized JSON Error Messages
241
254
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openaddresses/batch-schema",
3
3
  "root": true,
4
- "version": "2.3.4",
4
+ "version": "2.4.0",
5
5
  "description": "Strongly Validated JSON Schema support for address",
6
6
  "repository": "git@github.com:openaddresses/batch-schema",
7
7
  "author": "ingalls <nick@ingalls.ca>",