playcanvas / playcanvas/engine
Invalid json in case of failed load
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 16.8k
- Forks
- 2k
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 222
Description
If I try to load a JSON file and I have a loading error (for example "No Access-Control-Allow-Origin header is present") the xhr status is 0 and is considered as a success. I don't know if this is correct, but supposing it is, the result of the get request is an empty string that cannot be parsed:
Uncaught SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at Object._onSuccess (playcanvas-stable.dbg.js:20204)
at Object._onReadyStateChange (playcanvas-stable.dbg.js:20174)
at Object. (playcanvas-stable.dbg.js:20138)
So a simple patch would be to check for a not empty string before parsing, but I'm not sure if it's not better to understand why the xhr status zero is considered a successful request.
I had also an issue when the network was off. The get method doesn't return an error, but a successful empty result.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/net/http.js at line 372 and reproduce a JSON load with a CORS failure or the network offline. Trace how an XHR status of 0 and an empty response are handled before JSON.parse. Done means failed loads report an error instead of being treated as successful empty JSON results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100