From 7ffb9b89dcaaa3c94bad797b252b64c93c727e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Conde?= <16060539+joao-conde@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:54:35 +0000 Subject: [PATCH] feat: generic error message handling --- js/base.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/js/base.js b/js/base.js index 8324571..3f346af 100644 --- a/js/base.js +++ b/js/base.js @@ -97,13 +97,15 @@ export class API extends mix(BaseAPI).with( async _handleResponse(response, errorMessage = "Problem in request") { const result = await this._getResult(response); - const errors = - result.response && result.response.errors - ? result.response.errors.map(error => JSON.stringify(error)).join(",") - : null; - verify(!errors, errors, response.status || 500); - verify(!result.Fault, result.error || errorMessage, response.status || 500); - verify(response.ok, result.error || errorMessage, response.status || 500); + if (!response.ok) { + let error = null; + try { + error = JSON.stringify(result); + } catch { + error = errorMessage; + } + throw new OperationalError(error, response.status || 500); + } return result; }