From 3a4518619b1504cef050baf08a8cdb341a229fdf Mon Sep 17 00:00:00 2001 From: Helio Machado <0x2b3bfa0+git@googlemail.com> Date: Fri, 15 Apr 2022 01:19:28 +0200 Subject: [PATCH] Revert conditional chaining (#966) * Revert conditional chaining * Apply suggestions from code review Co-authored-by: DavidGOrtega * lint fix Co-authored-by: DavidGOrtega --- src/drivers/bitbucket_cloud.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/drivers/bitbucket_cloud.js b/src/drivers/bitbucket_cloud.js index b90a63211..e5adc57d2 100644 --- a/src/drivers/bitbucket_cloud.js +++ b/src/drivers/bitbucket_cloud.js @@ -379,9 +379,12 @@ class BitbucketCloud { // Attempt to get additional context. We have observed two different error schemas // from BitBucket API responses: `{"error": {"message": "Error message"}}` and // `{"error": "Error message"}`, apart from plain text responses like `Bad Request`. - const error = - responseBody?.error?.message || responseBody?.error || responseBody; - throw new Error(`${response.statusText} ${error}`.trim()); + const { error } = responseBody.error + ? responseBody + : { error: responseBody }; + throw new Error( + `${response.statusText} ${error.message || error}`.trim() + ); } return responseBody;