ソースを参照

ensure apiv3Err to accept Error instance

Yuki Takei 6 年 前
コミット
730644c9a8
2 ファイル変更5 行追加1 行削除
  1. 2 1
      src/server/models/ErrorV3.js
  2. 3 0
      src/server/routes/apiv3/response.js

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

@@ -1,9 +1,10 @@
 class ErrorV3 extends Error {
 
-  constructor(message = '', code = '') {
+  constructor(message = '', code = '', stack = undefined) {
     super(); // do not provide message to the super constructor
     this.message = message;
     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) {
         return e;
       }
+      if (e instanceof Error) {
+        return new ErrorV3(e.message, null, e.stack);
+      }
       if (typeof e === 'string') {
         return { message: e };
       }