From: Nick Downing Date: Tue, 25 Jan 2022 22:35:33 +0000 (+1100) Subject: Consistency changes for the Problem object X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?p=ndcode_site.git;a=commitdiff_plain;h=0bcb600b644042a1e2aa0d62a82e6b3cb9c89969 Consistency changes for the Problem object --- diff --git a/_config/Problem.mjs b/_config/Problem.mjs index 9d55df5..170b735 100644 --- a/_config/Problem.mjs +++ b/_config/Problem.mjs @@ -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 + ) ) } } diff --git a/_lib/Problem.jst b/_lib/Problem.jst index e403795..3b017c2 100644 --- a/_lib/Problem.jst +++ b/_lib/Problem.jst @@ -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 diff --git a/js/utils.js.min b/js/utils.js.min index b7dd5d2..89a90e1 100644 --- a/js/utils.js.min +++ b/js/utils.js.min @@ -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 + ) ) } }