sbefort / json-odds-api

This module is for retrieving odds data from the JSON Odds API. See https://jsonodds.com for more information.
5 stars 2 forks source link

Exception while Fetching odds from multiple sources one after another. #1

Closed srikanth-chitturi closed 7 years ago

srikanth-chitturi commented 8 years ago

One major issue we are facing is that some times there is an exception while fetching game data from multiple sources. I don't know what is causing this problem.

I am including my code , error and npm-debug.log file for your reference. please run this code on your side and test it.

Thanks in Advance. error.txt Error in Console multipleodds.js.txt My nodejs code of fetching game from multiple sources. npm-debug.log.txt npm debug log file

sbefort commented 8 years ago

Is this problem consistent, or intermittent? It looks like the JSON ODDS API is not returning JSON in the response. Instead, they are returning an HTML page that has "<" as the first character. That is invalid JSON so the request throws an error. Can you duplicate this problem every time?

srikanth-chitturi commented 8 years ago

No , I am sorry I can't duplicate the problem every time. But some times it does occur. I can say you the exact spot where the exception occurs each time.

sbefort commented 8 years ago

I think this is a problem with jsonodds.com returning an HTML page instead of JSON and not an actual problem with the node.js module I built. I would contact their support and ask them why they are sometimes returning HTML instead of JSON. Perhaps there is a temporary authentication issue that does not allow you to retrieve the JSON. Or perhaps there is a rate limit that is causing this. I'm just speculating, but it appears to be an issue that originates from jsonodds.com.

srikanth-chitturi commented 8 years ago

Yes , I believe so . Because when my json odds trail account has expired earlier , I received a html page in response. It might be something like that . Any ways thanks for your support .

On Sat, Jul 9, 2016 at 9:57 PM, Shaun Befort notifications@github.com wrote:

I think this is a problem with jsonodds.com returning an HTML page instead of JSON and not an actual problem with the node.js module I built. I would contact their support and ask them why they are sometimes returning HTML instead of JSON. Perhaps there is a temporary authentication issue that does not allow you to retrieve the JSON. Or perhaps there is a rate limit that is causing this. I'm just speculating, but it appears to be an issue that originates from jsonodds.com.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/sbefort/json-odds-api/issues/1#issuecomment-231542628, or mute the thread https://github.com/notifications/unsubscribe/ACCmJ2eVqn16rh3ja4RrsdwBggSjxXVOks5qT8vjgaJpZM4JFzW7 .

Thanks and Regards, Srikanth Chitturi,

sbefort commented 8 years ago

That makes sense. Okay I will close this issue.

srikanth-chitturi commented 8 years ago

No , don't close this issue . That was a problem earlier my trial account has expired, but now I have a Premium account purchased from jsonodds.com. And this issue is occurring now. I'll say if I can reproduce this issue . Thanks .

On Sun, Jul 10, 2016 at 9:46 PM, Shaun Befort notifications@github.com wrote:

Closed #1 https://github.com/sbefort/json-odds-api/issues/1.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/sbefort/json-odds-api/issues/1#event-718041649, or mute the thread https://github.com/notifications/unsubscribe/ACCmJ6IxY0l58dGqbH2u8NgNJIIbKd00ks5qURr5gaJpZM4JFzW7 .

Thanks and Regards, Srikanth Chitturi,

sbefort commented 8 years ago

Try to get the whole HTML contents that it is returning and paste them here.

srikanth-chitturi commented 8 years ago

"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r\n\r\n\r\n\r\n500 - Internal server error.\r\n\r\n\r\n\r\n

\r\n
\r\n
\r\n

500 - Internal server error.

\r\n

There is a problem with the resource you are looking for, and it cannot be displayed.

\r\n
\r\n
\r\n\r\n\r\n"

This might be caused by multiple requests passed simulatenously to jsonodds api , then there is a problem .

request.get(requestOptions, function (err, response, body) { if (err) return cb(err); if (!body || .isEmpty(JSON.parse(body))) return cb(null, ''); parse(body, function(err, parsed) { if (err) return cb(err); cb(null, response, parsed); }); }); At if (!body || .isEmpty(JSON.parse(body))) return cb(null, ''); the code is breaking .

sbefort commented 8 years ago

This is definitely an issue on their end. I would ask them why they are returning that error. Just to be clear, I have no relationship with jsonodds.com.

srikanth-chitturi commented 8 years ago

Hello ,

I have seen some exception occurring every time I request to jsonodds with nodejs package .

var options = {
    sport: req.body.sport,
    source:req.body.source
};
jsonOdds.getOdds(options, function(err, response, body) {
    if (err)
        throw new Error(err);
        if(body){
            res.json(body);
        }
        else{
            res.json('No Games');
        }
});

The parameters for options : 1. sport: soccer or nfl. source : 5. Response : Exception occurs

  1. sport : soccer source : 4 Response : No response comes back . Client have to wait forever .
srikanth-chitturi commented 7 years ago

The exceptions are occurring some times , when I pull game data from jsonodds api , can you confirm whether these things are occurring from JsonOdds or from npm module so that we can find a solution.

The code is crashing in here JsonOddsAPI.js :-

request.get(requestOptions, function (err, response, body) { if (err) return cb(err); if (!body || _.isEmpty(JSON.parse(body))) return cb(null, ''); parse(body, function(err, parsed) { if (err) return cb(err); cb(null, response, parsed); }); }); }).bind(this);

The crash message in terminal :

undefined:1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

SyntaxError: Unexpected token < at Object.parse (native) at Request._callback (/home/ubuntu/prodigyLeague/node_modules/json-odds-api/jsonOddsAPI.js:39:32) at Request.self.callback (/home/ubuntu/prodigyLeague/node_modules/json-odds-api/node_modules/request/request.js:200:22) at emitTwo (events.js:87:13) at Request.emit (events.js:172:7) at Request. (/home/ubuntu/prodigyLeague/node_modules/json-odds-api/node_modules/request/request.js:1067:10) at emitOne (events.js:82:20) at Request.emit (events.js:169:7) at IncomingMessage. (/home/ubuntu/prodigyLeague/node_modules/json-odds-api/node_modules/request/request.js:988:12) at emitNone (events.js:72:20) at IncomingMessage.emit (events.js:166:7) at endReadableNT (_stream_readable.js:921:12) at nextTickCallbackWith2Args (node.js:442:9) at process._tickCallback (node.js:356:17)

can you kindly give me a solution for this ? So that we can fix this issue. Or we can stop using npm module and start using the JsonOddsAPI directly if that might solve this issue.

sbefort commented 7 years ago

This is a problem with the JSON Odds API. I do not think that using the JSON Odds API directly is going to solve your issue because the same thing is going to happen. For whatever reason, they are sporadically returning HTML instead of JSON. This module has no control over that.

srikanth-chitturi commented 7 years ago

Thank you very much for your response. We'll contact the jsonodds team about this .

srikanth-chitturi commented 7 years ago

This is the HTML Output I get while the app crashes :

"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r\n<html xmlns="http://www.w3.org/1999/xhtml">\r\n<head>\r\n<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>\r\n<title>500 - Internal server error.</title>\r\n<style type="text/css">\r\n<!--\r\nbody{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}\r\nfieldset{padding:0 15px 10px 15px;} \r\nh1{font-size:2.4em;margin:0;color:#FFF;}\r\nh2{font-size:1.7em;margin:0;color:#CC0000;} \r\nh3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} \r\n#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;\r\nbackground-color:#555555;}\r\n#content{margin:0 0 0 2%;position:relative;}\r\n.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}\r\n-->\r\n</style>\r\n</head>\r\n<body>\r\n<div id="header"><h1>Server Error</h1></div>\r\n<div id="content">\r\n <div class="content-container"><fieldset>\r\n <h2>500 - Internal server error.</h2>\r\n <h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>\r\n </fieldset></div>\r\n</div>\r\n</body>\r\n</html>\r\n"

Is there any way that we can stop the application from crashing at this point : if (!body || _.isEmpty(JSON.parse(body))) return cb(null, ''); (JsonOddsAPI.js) line : 39

And just continue the execution of the program ?

srikanth-chitturi commented 7 years ago

I have written this fix in JsonOddsAPI.js : if(response.statusMessage === "Internal Server Error" || response.statusMessage === "Not Found"){ console.log('Error in JsonOdds API'); return cb(null,'') } else { if (!body || _.isEmpty(JSON.parse(body))) return cb(null, ''); parse(body, function(err, parsed) { if (err) return cb(err); cb(null, response, parsed); }); } So that the server doesn't crash suddenly if response is "Internal Server Error" or "Not Found", I think this will crash our application.

sbefort commented 7 years ago

That is a good idea. I will add the code to the module soon. Or you can send a pull request. Thanks.

sbefort commented 7 years ago

This should not be resolved with the latest pull request from @dangerisgo2021. Thanks for the pull request!

sbefort commented 7 years ago

I no longer have a paid membership to the JSON Odds API. Can someone upgrade to the new version 1.02 and test it?

dangerisgo2021 commented 7 years ago

upgraded. I don't know why JsonOdds is sending HTMl but now at least I can catch the error and my server doesn't go down

sbefort commented 7 years ago

These are not status codes from the JSON Odds API, but HTTP codes. There are a ton of them: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

This is why I have chosen to check for code 200 - OK.

srikanth-chitturi commented 7 years ago

Yeah Seems much better. I have installed latest version and tested it is working fine till now . No crashes.