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

Added error handling for github auth urls #4749

Merged
merged 5 commits into from
May 2, 2022

Conversation

Wazbat
Copy link
Contributor

@Wazbat Wazbat commented May 2, 2022

Changelog(Improvements): Improved error messages for Github Sync

I'm not sure how best show these errors to the user, but I feel that instead of these two console.error's that I added there should be some kind of error modal or something like that, but I'm not sure how best to do that in this project

@Wazbat Wazbat mentioned this pull request May 2, 2022
1 task
Copy link
Contributor

@jackkav jackkav left a comment

Choose a reason for hiding this comment

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

you'll need to copy the error setState hook and html in the same places as GitHubRepositoryForm

const [error, setError] = useState('');

          {error && (
            <p className="notice error margin-bottom-sm">
              <button className="pull-right icon" onClick={() => setError('')}>
                <i className="fa fa-times" />
              </button>
              {error}
            </p>
          )}

tuck it just inside the closing form tag

@Wazbat
Copy link
Contributor Author

Wazbat commented May 2, 2022

you'll need to copy the error setState hook and html in the same places as GitHubRepositoryForm

const [error, setError] = useState('');

          {error && (
            <p className="notice error margin-bottom-sm">
              <button className="pull-right icon" onClick={() => setError('')}>
                <i className="fa fa-times" />
              </button>
              {error}
            </p>
          )}

tuck it just inside the closing form tag

I appreciate that. I've gone ahead and added the code. I tested it locally and both errors show and appear to look fine.

Not sure if you'd like me to change the text, as it might be better to go with a more clear definitive The URL you entered is invalid instead of the vague mysterious It appears... message

image

image

@@ -368,20 +376,30 @@ const GitHubSignInForm = ({ token }: GitHubSignInFormProps) => {
});

command(dispatch);
} else {
setError('It appears the URL that you entered is incomplete');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
setError('It appears the URL that you entered is incomplete');
setError('Missing URL');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is "Missing URL" correct? It will only show this error if there is a valid url, howevever the state or code query params are missing

Perhaps Incomplete URL would be better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes I had misread because of the nested if statements perhaps you can use guard pattern to clear up the misunderstanding.

const hasCodeAndState = typeof code === 'string' && typeof state === 'string'
if(!hasCodeAndState) {
  setError('Incomplete URL');
  return;
}
const command = newCommand(COMMAND_GITHUB_OAUTH_AUTHENTICATE, {
  code,
  state,
});

command(dispatch);

Copy link
Contributor Author

@Wazbat Wazbat May 2, 2022

Choose a reason for hiding this comment

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

Gotcha. I've moved that logic up as requested and changed the error text, though I implemented it without the hasCodeAndState variable.

Is it still readable or would you prefer an additional variable to make it easier to understand when glancing over the code?

@filfreire filfreire enabled auto-merge (squash) May 2, 2022 20:35
@filfreire filfreire merged commit a8407b6 into Kong:develop May 2, 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.

3 participants