Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

check for error before looking at response #6

Merged
merged 3 commits into from

2 participants

@schnie

Occasionally an error will occur on the requests so we need to check for an error as well as the 200 in the response. If we don't check for the error you can get a "cannot read statusCode of undefined" error and the app crashes.

index_mlb.js
@@ -77,9 +77,10 @@ function getTeamsHierarchy(callback, event) {
function createRequest(url, callback) {
+ console.log(url);
@rgerard Owner
rgerard added a note

Could you remove this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rgerard rgerard commented on the diff
.gitignore
@@ -36,3 +36,5 @@ Thumbs.db
node_modules/
.idea/
+*.sublime-workspace
+*.sublime-project
@rgerard Owner
rgerard added a note

Looks like you need a newline here

@schnie
schnie added a note

sorry about that - fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Greg Neiheisel added some commits
Greg Neiheisel Update .gitignore 4f71745
Greg Neiheisel Update index_mlb.js 0f14a37
@rgerard rgerard merged commit ac67bc0 into rgerard:master
@rgerard
Owner

NPM package has been published as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 14, 2014
  1. check for error before looking at response

    schnie authored
Commits on May 15, 2014
  1. Update .gitignore

    Greg Neiheisel authored
  2. Update index_mlb.js

    Greg Neiheisel authored
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -36,3 +36,5 @@ Thumbs.db
node_modules/
.idea/
+*.sublime-workspace
+*.sublime-project
@rgerard Owner
rgerard added a note

Looks like you need a newline here

@schnie
schnie added a note

sorry about that - fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
5 index_mlb.js
@@ -77,9 +77,10 @@ function getTeamsHierarchy(callback, event) {
function createRequest(url, callback) {
+
request(url, function (error, response, body) {
- if (response.statusCode == 200) {
+ if (!error && response.statusCode == 200) {
// Parse the XML to JSON
parser.parseString(body, function (err, result) {
@@ -140,4 +141,4 @@ module.exports = {
getTeamsHierarchy: function(callback) {
return getTeamsHierarchy(callback);
}
-};
+};
View
2  index_nba.js
@@ -69,7 +69,7 @@ function getRoster(teamID, callback) {
function createRequest(url, callback) {
request(url, function (error, response, body) {
- if (response.statusCode == 200) {
+ if (!error && response.statusCode == 200) {
// Parse the XML to JSON
parser.parseString(body, function (err, result) {
View
2  index_ncaaf.js
@@ -64,7 +64,7 @@ function getTeamHierarchy(division, callback) {
function createRequest(url, callback) {
request(url, function (error, response, body) {
- if (response.statusCode == 200) {
+ if (!error && response.statusCode == 200) {
// Parse the XML to JSON
parser.parseString(body, function (err, result) {
View
2  index_nfl.js
@@ -119,7 +119,7 @@ function getSeasonalStats(team, callback) {
function createRequest(url, callback) {
request(url, function (error, response, body) {
- if (response.statusCode == 200) {
+ if (!error && response.statusCode == 200) {
// Parse the XML to JSON
parser.parseString(body, function (err, result) {
View
2  index_nhl.js
@@ -49,7 +49,7 @@ function getStandings(callback) {
function createRequest(url, callback) {
request(url, function (error, response, body) {
- if (response.statusCode == 200) {
+ if (!error && response.statusCode == 200) {
// Parse the XML to JSON
parser.parseString(body, function (err, result) {
Something went wrong with that request. Please try again.