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

Add onerror example #439

Merged
merged 2 commits into from
Nov 19, 2019
Merged

Conversation

beaufortfrancois
Copy link
Collaborator

@beaufortfrancois beaufortfrancois commented Nov 7, 2019

This PR addresses comment posted by @reillyeon in #432 (comment)


Preview | Diff

index.html Outdated Show resolved Hide resolved
@beaufortfrancois
Copy link
Collaborator Author

Let's wait for @reillyeon to review before merging.

index.html Outdated
reader.scan().then(() => {
console.log("Scan started successfully.");
reader.onerror = event => {
console.log("Error! Cannot read data from NFC tag.");
Copy link
Member

Choose a reason for hiding this comment

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

The log message below says "try again" but this case is really the one were retrying makes sense (tell the user to hold their device against the tag for longer) whereas an error below indicates a more fatal issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The onerror event is raised only for IOException and FormatException, not TagLostException. I believe* this means holding device longer won't change anything. Both are fatal errors.
Do you want to me remove "try again" to make it clearer?

Throws Reason
TagLostException if the tag leaves the field
IOException if there is an I/O failure, or the operation is canceled
FormatException if the NDEF Message on the tag is malformed

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Do you think we should fire an event on TagLostException? That seems like the most likely and most actionable error that a site could encounter.

Given the current behavior I would word the error as, "Error! Cannot read data from the NFC tag. Try a different one?"

My goal is for this example code to demonstrate to developers what parts of their UI should be responding to different events, and how. This also gives us a good opportunity to test whether or not developers will be able to easily code against these potential errors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think TagLostExceptionprovides that much value as users will try again if they see app is not reacting, while IOException and FormatException are more "It's over" errors. They're nothing users can do about it as they use wrong formatted tags, and website will only show them something like "Sorry! This tag is not compatible with this application".

I'll update my example with your error message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See c5109bc

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