Skip to content

Added error codes to errors. #26

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Aaronius
Copy link
Contributor

Description

In #11, I described how error codes could be added to errors so consumers could programmatically figure out why jwt-auth failed and react accordingly. I think there was a miscommunication though because the codes were added to the error message itself rather than a property directly on the error. While consumer code could search for a particular error code within the error message, programmatically reacting to text within the message is usually frowned upon as the message is considered subject to change and isn't intended for programmatic decisioning.

In this PR, I'm demonstrating how we could add a code property to the error objects. The possible error codes are the ones found at the top of index.js and those in the Responses section of the endpoint documentation.

I haven't added tests or updated the readme yet. I wanted to see if you would be amenable to this change first.

Related Issue

#9

Motivation and Context

Programmatically determine what caused an error to occur.

How Has This Been Tested?

So far, only manual testing.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

.then(res => res.json())
.catch(e => throwRequestFailedError(e.message))
.then(res => {
// if (res.ok) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interestingly, even when the swap was successful, res.ok is false and the status code is 400. I don't know why this is happening.

@shazron
Copy link
Member

shazron commented Mar 3, 2020

Tests are failing (they were not updated)

@Aaronius
Copy link
Contributor Author

@shazron (or anyone else maintaining this library), is this PR something you would consider? If so, we can update tests, but I didn't want to update tests until I got an idea of whether something like this would be accepted.

@brenthosie
Copy link
Member

Can we please get a response on this PR? This blocks adobe/reactor-uploader#28 for us.

@macdonst
Copy link
Contributor

Yes, we'd be good with the PR. Just need to update those tests and we'll release a new major as not to break folks who depend on the old behaviour.

@brenthosie brenthosie mentioned this pull request Apr 22, 2021
10 tasks
@brenthosie
Copy link
Member

Resolved by #52 and #53

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