Skip to content
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

Fix authentication error payload #360

Merged
merged 10 commits into from
Sep 10, 2024
Merged

Conversation

PaulAsjes
Copy link
Contributor

Description

Exceptions were only returning specific hardcoded values, which isn't accurate any more since an error can have a plethora of parameters in it.

This fixes it by dumping the contents of the API response into the error object, giving the user all the information they need to fix the error.

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

@PaulAsjes PaulAsjes requested a review from a team as a code owner September 9, 2024 11:58
)
except Exception as ex:
assert ex.__class__ == BadRequestException

def test_bad_request_exceptions_exclude_expected_request_data(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What we want is for everything in the return value to be added to exceptions, this test does the opposite.

def __str__(self) -> str:
message = self.message or "No message"
exception = "(message=%s" % message
self.message = self.extractFromJson("message", "No message")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is 100x nicer than except ValueError, good stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Also lol snake case

self.error = self.extractFromJson("error", None)
self.errors = self.extractFromJson("errors", None)
self.code = self.extractFromJson("code", None)
self.error_description = self.extractFromJson("error_description", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

error and error_description previously defaulted to "Unknown" so this is a small change in behavior (line)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good catch!

@azuline
Copy link

azuline commented Sep 10, 2024

thank you!

@PaulAsjes PaulAsjes merged commit 82eac1c into main Sep 10, 2024
5 checks passed
@PaulAsjes PaulAsjes deleted the fix/authentication-error-payload branch September 10, 2024 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants