Skip to content

Add response content to ApiException class #83

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
merged 1 commit into from
May 23, 2022

Conversation

Anton0
Copy link
Contributor

@Anton0 Anton0 commented Mar 15, 2022

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

adds a response field to the staxapp.exceptions.ApiException class, this allows users to use the response even in error scenarios, an example might be when creating an account type that already exists the API returns HTTP/400 which the SDK raises an exception for, however the api returns the details about the existing account-type but doesn't pass them back to the calling code.

example

    except ApiException as e:
        if e.status_code == 400:
            print(e.response['Detail']['AccountType']['Id'])

this means the user needs to make another get call just to get the existing ID

  • What is the current behavior? (You can also link to an open issue here)

the response data (json or otherwise) is logged but not stored meaning users need to make a second call or attempt to string parse the logs 🙅

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

no - this only adds a new attribute to an existing class

@codecov
Copy link

codecov bot commented Mar 15, 2022

Codecov Report

Merging #83 (157ff91) into master (d9c857f) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master       #83   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines          434       436    +2     
=========================================
+ Hits           434       436    +2     
Impacted Files Coverage Δ
staxapp/exceptions.py 100.00% <100.00%> (ø)

@Anton0 Anton0 marked this pull request as ready for review March 15, 2022 05:06
@Anton0 Anton0 requested a review from a team as a code owner March 15, 2022 05:06
Copy link
Contributor

@ZXYmania ZXYmania left a comment

Choose a reason for hiding this comment

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

Looking at the Api Spec we only return Cause and Error for an Error response json. Allowing Customers to see the response may confuse them as to why some have content and others may not. With this in mind are the changes worthwhile? I now see you've given a valid use case but I do worry about exposing the inconsistencies of the api

@samdammers
Copy link
Contributor

samdammers commented Mar 15, 2022

I would like further discussions on error responses, but providing access to the content is a good start.

@Anton0
Copy link
Contributor Author

Anton0 commented May 23, 2022

Yup - valid concerns, but in lieu of more consistent API responses provided access to the existing responses I suspect is still better than requiring capturing stdout

@Anton0 Anton0 merged commit cfdd181 into master May 23, 2022
@Anton0 Anton0 deleted the add-response-to-api-exception branch May 23, 2022 01:06
@Anton0 Anton0 added the enhancement New feature or request label May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants