فهرست منبع

Adjusted http-error-handler for http-errors@1.7.2

hakumizuki 4 سال پیش
والد
کامیت
92988d2c00
1فایلهای تغییر یافته به همراه16 افزوده شده و 1 حذف شده
  1. 16 1
      src/server/middlewares/http-error-handler.js

+ 16 - 1
src/server/middlewares/http-error-handler.js

@@ -1,4 +1,19 @@
-const { isHttpError } = require('../../../node_modules/http-errors');
+const { HttpError } = require('../../../node_modules/http-errors');
+
+const isHttpError = (val) => {
+  if (!val || typeof val !== 'object') {
+    return false;
+  }
+
+  if (val instanceof HttpError) {
+    return true;
+  }
+
+  return val instanceof Error
+    && typeof val.expose === 'boolean'
+    && typeof val.statusCode === 'number'
+    && val.status === val.statusCode;
+};
 
 module.exports = (err, req, res, next) => {
   // handle if the err is a HttpError instance