Kaynağa Gözat

ensure apiv3Err to accept Error instance

Yuki Takei 6 yıl önce
ebeveyn
işleme
730644c9a8

+ 2 - 1
src/server/models/ErrorV3.js

@@ -1,9 +1,10 @@
 class ErrorV3 extends Error {
 class ErrorV3 extends Error {
 
 
-  constructor(message = '', code = '') {
+  constructor(message = '', code = '', stack = undefined) {
     super(); // do not provide message to the super constructor
     super(); // do not provide message to the super constructor
     this.message = message;
     this.message = message;
     this.code = code;
     this.code = code;
+    this.stack = stack;
   }
   }
 
 
 }
 }

+ 3 - 0
src/server/routes/apiv3/response.js

@@ -22,6 +22,9 @@ const addCustomFunctionToResponse = (express, crowi) => {
       if (e instanceof ErrorV3) {
       if (e instanceof ErrorV3) {
         return e;
         return e;
       }
       }
+      if (e instanceof Error) {
+        return new ErrorV3(e.message, null, e.stack);
+      }
       if (typeof e === 'string') {
       if (typeof e === 'string') {
         return { message: e };
         return { message: e };
       }
       }