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

Wrong error message in case of network error #153

Closed
Gargair opened this issue Jun 19, 2023 · 2 comments
Closed

Wrong error message in case of network error #153

Gargair opened this issue Jun 19, 2023 · 2 comments
Assignees
Labels

Comments

@Gargair
Copy link

Gargair commented Jun 19, 2023

DynamicsWebApi version
For example: v1.7.6

Describe the bug
In case of a client side network error the returned error message is "Unexpected Error" instead of "Network Error".
Additionally a NPE will be logged in the console. (TypeError: Cannot read properties of null (reading 'getAllResponseHeaders'))

Expected behavior
A single error with the expected error message

Steps To Reproduce

  1. Open DevTools
  2. Go to Network tab
  3. Set mode to offline
  4. Send request

Your Setup:

  • Chrome 114.0.5735.111
  • Dynamics 365 Online

Additional context
The problem is the incorrect error handling in case of a network error.
In case of client side network errors the request will be instantly completed with a status of 0. As such the onreadystatechange function is called with readyState 4 and request.status 0. The library then fails to parse the response and returns an error message of "Unexpected Error". And dereferences the request.
After that the onerror function is called which then errors out due to a NPE.

The correct handling would be to explicitly ignore a request.status of 0 in onreadystatechange function. In these cases the onerror function will be called.

From https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/status:

Before the request completes, the value of status is 0. Browsers also report a status of 0 in case of XMLHttpRequest errors.

@AleksandrRogov
Copy link
Owner

@Gargair thank you for submitting an issue. I will look into it.

@AleksandrRogov AleksandrRogov self-assigned this Jun 19, 2023
@AleksandrRogov AleksandrRogov moved this to In Progress in DynamicsWebApi v2 Jul 11, 2023
AleksandrRogov added a commit that referenced this issue Jul 14, 2023
… files; removing unused code; adding more unit tests; adding v1 github action to test the package
@AleksandrRogov
Copy link
Owner

Fixed in v.1.7.11. Thank you for reporting it @Gargair .

@github-project-automation github-project-automation bot moved this from In Progress to Done in DynamicsWebApi v2 Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants