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

Adding throw to authentication fails #7

Closed
wants to merge 1 commit into from
Closed

Adding throw to authentication fails #7

wants to merge 1 commit into from

Conversation

xguhx
Copy link

@xguhx xguhx commented Nov 1, 2021

Hey,
This tries to fix #5.
I added a throw to the unauthorized requests on line 957.

Please let me know if I need to make any changes.
Thank you

@xguhx xguhx requested a review from a team as a code owner November 1, 2021 02:35
@xguhx xguhx requested review from jsmvaldivia and removed request for a team November 1, 2021 02:35
@jsmvaldivia jsmvaldivia requested a review from jcrqr November 4, 2021 13:26
Copy link
Contributor

@jcrqr jcrqr left a comment

Choose a reason for hiding this comment

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

Hey @GMOTGIT 👋🏼! Thanks a lot for your contribution, it's very welcomed!

The changes you've done would eventually work, since you've replaced the return with a throw, and we handle that when we call the createRemoteLink function. However, the place where you've done this change is not the best, since you've updated the build artifact of the main source code, which will get replaced if do any change to the original source code, the index.js file.

I suggest you to handle this in a slightly different way so that your changes don't get overwritten in the future.

Since what we want to achieve is to check if the HTTP call we're doing returns an authentication/authorization error (which in HTTP terms means the status code of the response will be either 401 or 403, respectively), a more "bullet-proof" approach would be to check if the response we're receiving has either of those status codes.

If you look closely, we're using the Fetch API to perform the HTTP request. The return of that function is of type Response, and includes a property called status, which is a number representing the status code of the response.

We could use that to easily check and validate our request was successfully completed and didn't had any authentication error.

On L#44 when we do the request, instead of returning immediately the result of that call, we could instead put it in a variable, validate the status code, throw an error in case the call wasn't successful or return the response as-is and let the program continue on.

Something like this:

const resp = await fetch(...);

if (resp.status === 401) {
  throw new Error("unauthenticated");
}

if (resp.status === 403) {
  throw new Error("unauthorized");
}

return resp;

Please, let me know if this helps you or if you've any further questions. We're happy to on-board you and help you however you need! GJ 👍🏼

@xguhx xguhx closed this by deleting the head repository Oct 20, 2022
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.

When authentication fails the action should throw an error and exit
2 participants