expressa 2.0.2 → 2.0.3

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.
@@ -4,6 +4,16 @@ const util = require('../util')
4
4
 
5
5
  module.exports = function logRequests(req, res, next) {
6
6
  if (req.db.requestlog) {
7
+ const oldSend = res.send
8
+ res.send = function(...params) {
9
+ const data = params[0]
10
+ // ensure requests using custom middleware log error messages
11
+ if (typeof data?.error === 'string') {
12
+ req.returnedError ??= new util.ApiError(res.statusCode, data.error)
13
+ }
14
+ res.send = oldSend // set function back to avoid the 'double-send'
15
+ return res.send(...params) // just call as normal with data
16
+ }
7
17
  onFinished(res, async function (err) {
8
18
  if (err) {
9
19
  console.error('error found while logging.')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expressa",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "API framework using JSON schemas",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/thomas4019/expressa",