glantucan Posted August 20, 2015 Share Posted August 20, 2015 HiI found out that when loading json files with game.load.json() if the file is not found the onFileError signal fires after the Phaser.Loader.jsonLoadComplete() function is executed which produces a parsing error as the server is responding with HTML<!doctype html><title>404 Not Found</title><h1 style="text-align: center">404 Not Found</h1><hr/><p style="text-align: center">WebStorm 10.0.4</p>This avoids the detection of the actual error. So I can do nothing to amend it. Does anyone knows how to solve this? Thanks in advance Link to comment Share on other sites More sharing options...
glantucan Posted August 21, 2015 Author Share Posted August 21, 2015 Nobody? Let me explain a little what I am trying to achieve. I am building an educational game with several minigames inside (drag and drop, card match, etc. most of them point and click ) As the games all are the same on each subject it tries to teach the configuration files are almost the same for each subject. But sometimes some texts don't fit in the space they have reserved, so I have to change the fon size, or for a particular subject there is a different background to load, etc., etc. There can be a lot of mimimal changes like those. Being so, I thought to keep a small json conf file for each common gameObject in the minigames. Each of those have a default version that is always loaded and can have a 'per subject' version that takes care of the difference. But I am stuck with the error explained above, I planned to use the default conf files as fallbacks when the 'per subject' version wold get a FIleError event, whic I cannot get in time because the JSON parsing error gets in the way. Hope it is clearer now Thanks Link to comment Share on other sites More sharing options...
drhayes Posted August 21, 2015 Share Posted August 21, 2015 I'm thinking your best bet would be to include those files in the page and skip the loader entirely. Depending how many of those files there are or how big they are your load time probably wouldn't be increased too badly. E.g. think about the size of one of your JSON files vs. one of your images; I bet the JSON files are tiny, relatively speaking. Failing that, make one JSON file named "overrides.json" (or something) and load that. Make each of its keys the name of the object you're overriding. Failing even *that*, customize the 404 page for whatever server you're using to either return a blank body during 404, or return a minimal JSON doc. That seems unnecessarily brittle, though – you'd have to worry about what happens to your game when someone changes a config or you move it to a different server. Link to comment Share on other sites More sharing options...
glantucan Posted August 21, 2015 Author Share Posted August 21, 2015 Thanks drHayes Sort of already did wht you suggest. I always load a defaults json and a 'per subject' json with all the configuration so there is always afile to load in both cases. I don't want to include them in the page as it is always the same and also prefer to have things as modular as possible. And you are right, changing 404 page on the server didn't feel like the solution. Anyway, do you know if this behavior is normal, I mean, a feature or may be a Phaser bug? Link to comment Share on other sites More sharing options...
drhayes Posted August 24, 2015 Share Posted August 24, 2015 "Normal", I guess? You're telling Phaser to load JSON but your server is handing it HTML. ¯\_(ツ)_/¯ Link to comment Share on other sites More sharing options...
glantucan Posted August 24, 2015 Author Share Posted August 24, 2015 "Normal", I guess? You're telling Phaser to load JSON but your server is handing it HTML. ¯\_(ツ)_/¯ Maybe it's because I don't know so much about http but shouldn't I receive the http error. Or it's a question of how the server is configured too? Link to comment Share on other sites More sharing options...
drhayes Posted August 25, 2015 Share Posted August 25, 2015 Phaser creates an XMLHttpRequest to load JSON files and specifies the response type as "text". An XHR's onerror handler only fires if there's an error at the network level, i.e. the server is completely unreachable or the user's network cable is disconnected. If the server successfully responded, even with a 404, then the XHR's onload will fire... which means that Phaser gets a crack at interpreting the results of the XHR which, in your case, is an HTML page. Phaser doesn't look at the status of the XHR, only the response. Hence the shrug. Does this make sense? Link to comment Share on other sites More sharing options...
glantucan Posted August 26, 2015 Author Share Posted August 26, 2015 Yes. It does Thank you very much. Now I understand it. Link to comment Share on other sites More sharing options...
Recommended Posts