Skip to content

Improve BitBucket unauthorized error message - #813

Merged
0x2b3bfa0 merged 2 commits into
masterfrom
improve-bitbucket-unauthorized-error
Nov 17, 2021
Merged

0x2b3bfa0 merged 2 commits into
masterfrom
improve-bitbucket-unauthorized-error

Conversation

@duijf

@duijf duijf commented Nov 17, 2021

Copy link
Copy Markdown
Contributor

Was playing around with CML for some integration work with Studio when I encountered this papercut.

On 401 unauthorized responses, the BitBucket API does not always return a JSON body. That was causing the error handling code that's being changed here to throw an error itself, which led to errors like:

error: invalid json response body at [url] reason: Unexpected end of JSON input {"type":"invalid-json"}

Which was a bit confusing to me. This commit changes the error handling code to return a generic error message instead. So with an incorrect BitBucket token, CML now prints:

error: Unauthorized

Which should be a little more helpful to the user.

NB: My JS is not the best ever, so if something looks weird / unidiomatic, it probably is. Please let me know if you'd like to see any changes :)

On 401 unauthorized responses, BitBucket does not always return a JSON
body. That was causing the error handling code that's being changed here
to throw an error itself, which led to errors like:

```
error: invalid json response body at [url] reason: Unexpected end of JSON input {"type":"invalid-json"}
```

Which was a bit confusing to me. This commit changes the error handling
code to return a generic error message instead. So with an incorrect
BitBucket token, CML now prints:

```
error: Unauthorized
```

Which should be more helpful to the user.
@duijf
duijf requested a review from a team November 17, 2021 16:37
@duijf
duijf temporarily deployed to internal November 17, 2021 16:37 Inactive
@duijf duijf self-assigned this Nov 17, 2021
Comment thread src/drivers/bitbucket_cloud.js Resolved
Co-authored-by: Helio Machado <[email protected]>
@duijf
duijf temporarily deployed to internal November 17, 2021 16:57 Inactive

@0x2b3bfa0 0x2b3bfa0 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

@duijf

duijf commented Nov 17, 2021

Copy link
Copy Markdown
Contributor Author

GitLab CI failed with an error from Terraform. I don't have enough context to easily see what's happening there, but it looks like a timeout that's unrelated to the changes here.

@0x2b3bfa0
0x2b3bfa0 merged commit 44806c0 into master Nov 17, 2021
@0x2b3bfa0
0x2b3bfa0 deleted the improve-bitbucket-unauthorized-error branch November 17, 2021 17:18
@0x2b3bfa0

Copy link
Copy Markdown
Member

@0x2b3bfa0

Copy link
Copy Markdown
Member

GitLab CI failed with an error from Terraform. I don't have enough context to easily see what's happening there, but it looks like a timeout that's unrelated to the changes here.

This happens because the spot instance request didn't get fulfilled before the 10 minute deadline. The error is because we lack enough permissions to remove the request, but it would have failed anyway.

@DavidGOrtega

Copy link
Copy Markdown
Contributor

Thanks for the contribution ❤️ @duijf now we feel obligated to break Viewer... somehow 😁

This branch was previously deployed

1 inactive deployment
internal — a01b6931 Deployed Nov 17, 2021 by duijf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants