Skip to content

Bitbucket Cloud: provide custom raise_for_status #925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

flichtenheld
Copy link
Contributor

The default one in AtlassianRestAPI does not work
for Bitbucket Cloud.

Signed-off-by: Frank Lichtenheld frank@lichtenheld.com

The default one in AtlassianRestAPI does not work
for Bitbucket Cloud.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
@flichtenheld
Copy link
Contributor Author

Found this one while trying to make #904 work for Bitbucket Cloud.

@slmnsh
Copy link

slmnsh commented Jan 19, 2022

It'll be better if we just revert 50b5c71 instead of adding error handling one by one

@flichtenheld
Copy link
Contributor Author

It'll be better if we just revert 50b5c71 instead of adding error handling one by one

What was the behavior before? To me it looks like before it just used the HTTP error message which is useless in many cases. It is definitely better to show the actual error message from the JSON response. But it seems that the JSON format is different for each service...

@slmnsh
Copy link

slmnsh commented Jan 19, 2022

It'll be better if we just revert 50b5c71 instead of adding error handling one by one

What was the behavior before? To me it looks like before it just used the HTTP error message which is useless in many cases. It is definitely better to show the actual error message from the JSON response. But it seems that the JSON format is different for each service...

If you look the tagged commit carefully you'll see it was showing proper error message from json data. Also it has different error handling for each service.

@flichtenheld
Copy link
Contributor Author

It'll be better if we just revert 50b5c71 instead of adding error handling one by one

What was the behavior before? To me it looks like before it just used the HTTP error message which is useless in many cases. It is definitely better to show the actual error message from the JSON response. But it seems that the JSON format is different for each service...

If you look the tagged commit carefully you'll see it was showing proper error message from json data. Also it has different error handling for each service.

That might be true for some services, but that commit did not remove any error handling from atlassian/bitbucket. I just verified that. Without my patch and with the referenced commit reverted you get something like (for a random error that I hit today):

requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.bitbucket.org/2.0/repositories/openvpntechnologies/ovpn3-build/commit/4e857d6c9df6956932ed0b25abb8454892dcebea/statuses/build

With my patch you get:

requests.exceptions.HTTPError: Authenticated user is neither the creator (frank_lichtenheld) of this build status nor an admin of this repository.

So I think this is a definite improvement for Bitbucket Cloud specifically.

@slmnsh
Copy link

slmnsh commented Jan 20, 2022

It'll be better if we just revert 50b5c71 instead of adding error handling one by one

What was the behavior before? To me it looks like before it just used the HTTP error message which is useless in many cases. It is definitely better to show the actual error message from the JSON response. But it seems that the JSON format is different for each service...

If you look the tagged commit carefully you'll see it was showing proper error message from json data. Also it has different error handling for each service.

That might be true for some services, but that commit did not remove any error handling from atlassian/bitbucket. I just verified that. Without my patch and with the referenced commit reverted you get something like (for a random error that I hit today):

requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.bitbucket.org/2.0/repositories/openvpntechnologies/ovpn3-build/commit/4e857d6c9df6956932ed0b25abb8454892dcebea/statuses/build

With my patch you get:

requests.exceptions.HTTPError: Authenticated user is neither the creator (frank_lichtenheld) of this build status nor an admin of this repository.

So I think this is a definite improvement for Bitbucket Cloud specifically.

How about reverting that commit and keeping your patch too?

@flichtenheld
Copy link
Contributor Author

How about reverting that commit and keeping your patch too?

I don't have a specific opinion on that. But I will definitely not make that part of my PR.

@gonchik
Copy link
Member

gonchik commented Jan 24, 2022

@salmannotkhan does it really need to be revert it ?
I dig into code, it was to quite duplication.
I will be happy to understand the exact usage

@gonchik gonchik merged commit 588897e into atlassian-api:master Jan 24, 2022
@slmnsh
Copy link

slmnsh commented Jan 25, 2022

@salmannotkhan does it really need to be revert it ?
I dig into code, it was to quite duplication.
I will be happy to understand the exact usage

Okay, let me explain what happened.

I'm using this library for 6 months never faced any issues. But one day I was making a python script to update labels on every bitbucket that I have.

I didn't know that repo labels can't contain uppercase characters. So I tried to set labels that are uppercase but instead of returning the error from API saying that "Labels can't contain the uppercase letter" I got a KeyError: "errorMessage" key doesn't exist on d or Something like that.

That means error messages aren't handled properly after the try to handle all errors messages singly because each service has its error message format.

@gonchik
Copy link
Member

gonchik commented Jan 25, 2022

@salmannotkhan noted thank you. My bad in that situation.
Is it ok if start only for BB cloud, because I use for Jira, Confluence on-prem and error handling works well?
Or I use a little bit in other way then other developers

@slmnsh
Copy link

slmnsh commented Jan 25, 2022

@salmannotkhan noted thank you. My bad in that situation.
Is it ok if start only for BB cloud, because I use for Jira, Confluence on-prem and error handling works well?
Or I use a little bit in other way then other developers

Yup only BB cloud will be fine for now because that is only causing errors for me

@gonchik
Copy link
Member

gonchik commented Jan 25, 2022

@salmannotkhan let me upload a new release.
Too bad to read once someone meet errors

@slmnsh
Copy link

slmnsh commented Jan 25, 2022

@salmannotkhan let me upload a new release.
Too bad to read once someone meet errors

No problem, sir it's a great library for atlassian services

@clrusby
Copy link

clrusby commented Jan 28, 2022

@gonchik - given it does affect other clients (eg bitbucket server), could we amend your commit 50b5c71 so it reads something like this instead?

error_msg = "\n".join(j.get("errorMessages", []) + [k + ": " + v for k, v in j.get("errors", {}).items()])

@gonchik
Copy link
Member

gonchik commented Jan 29, 2022

@clrusby sure!

@clrusby
Copy link

clrusby commented Jan 29, 2022

What I wrote doesn’t actually work for bitbucket server as errors is a list of dict.
It does get a bit messy to handle it generically here, which makes me wonder whether it’s better to add a bespoke error handler for bitbucket server.

@flichtenheld flichtenheld deleted the bitbucket-raise-for-status branch February 8, 2022 12:31
gonchik pushed a commit that referenced this pull request Sep 3, 2022
The default one in AtlassianRestAPI does not work
for Bitbucket Cloud.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
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.

4 participants