Consistency changes for the Problem object
authorNick Downing <nick@ndcode.org>
Tue, 25 Jan 2022 22:35:33 +0000 (09:35 +1100)
committerNick Downing <nick@ndcode.org>
Tue, 25 Jan 2022 23:13:22 +0000 (10:13 +1100)
_config/Problem.mjs
_lib/Problem.jst
js/utils.js.min

index 9d55df5..170b735 100644 (file)
@@ -5,11 +5,17 @@ class Problem {
     this.status = status
   }
 
+  // note: Javascript errors return status 400 (Bad request) in the client
+  // version of Problem, 500 (Internal server error) in the server version
   static from(error) {
     return (
       error instanceof Problem ?
         error :
-        new Problem('Bad request', (error.stack || error.message), 400)
+        new Problem(
+          'Bad request',
+          (error.stack || error.message),
+          400
+        )
     )
   }
 }
index e403795..3b017c2 100644 (file)
@@ -4,6 +4,20 @@ class Problem {
     this.detail = detail
     this.status = status
   }
+
+  // note: Javascript errors return status 400 (Bad request) in the client
+  // version of Problem, 500 (Internal server error) in the server version
+  static from(error) {
+    return (
+      error instanceof Problem ?
+        error :
+        new Problem(
+          'Internal server error',
+          (error.stack || error.message),
+          500
+        )
+    )
+  }
 }
 
 return Problem
index b7dd5d2..89a90e1 100644 (file)
@@ -72,11 +72,17 @@ Problem = class {
     this.status = status
   }
 
+  // note: Javascript errors return status 400 (Bad request) in the client
+  // version of Problem, 500 (Internal server error) in the server version
   static from(error) {
     return (
       error instanceof Problem ?
         error :
-        new Problem('Bad request', (error.stack || error.message), 400)
+        new Problem(
+          'Bad request',
+          (error.stack || error.message),
+          400
+        )
     )
   }
 }