Skip to content

Commit

Permalink
Better error reporting for BitBucket (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
duijf authored Nov 19, 2021
1 parent 44806c0 commit 0a674fe
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/drivers/bitbucket_cloud.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fetch = require('node-fetch');
const winston = require('winston');
const { URL } = require('url');
const ProxyAgent = require('proxy-agent');

Expand Down Expand Up @@ -245,7 +246,10 @@ class BitbucketCloud {
Authorization: 'Basic ' + `${token}`
};

const response = await fetch(url || `${api}${endpoint}`, {
const requestUrl = url || `${api}${endpoint}`;
winston.debug(`${method} ${requestUrl}`);

const response = await fetch(requestUrl, {
method,
headers,
body,
Expand All @@ -254,10 +258,12 @@ class BitbucketCloud {

if (response.status > 300) {
try {
const {
error: { message }
} = await response.json();
throw new Error(message);
const json = await response.json();
winston.debug(json);
// Attempt to get additional context. We have observed two different error schemas
// from BitBucket API responses: `{"error": {"message": "Error message"}}` and
// `{"error": "Error message"}`.
throw new Error(json.error.message || json.error);
} catch (err) {
throw new Error(`${response.statusText} ${err.message}`);
}
Expand Down

1 comment on commit 0a674fe

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

Please sign in to comment.