()
| 324 | var response = null; |
| 325 | |
| 326 | var onRequestComplete = function () { |
| 327 | if (body !== '') { |
| 328 | try { |
| 329 | body = JSON.parse(body) |
| 330 | } catch (jsonDecodeError) { |
| 331 | // there was no transport-level error, but a JSON object could not be decoded from the request body |
| 332 | // surface this to the caller |
| 333 | var err = helpers.makeTwitError('JSON decode error: Twitter HTTP response body was not valid JSON') |
| 334 | err.statusCode = response ? response.statusCode: null; |
| 335 | err.allErrors.concat({error: jsonDecodeError.toString()}) |
| 336 | callback(err, body, response); |
| 337 | return |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | if (typeof body === 'object' && (body.error || body.errors)) { |
| 342 | // we got a Twitter API-level error response |
| 343 | // place the errors in the HTTP response body into the Error object and pass control to caller |
| 344 | var err = helpers.makeTwitError('Twitter API Error') |
| 345 | err.statusCode = response ? response.statusCode: null; |
| 346 | helpers.attachBodyInfoToError(err, body); |
| 347 | callback(err, body, response); |
| 348 | return |
| 349 | } |
| 350 | |
| 351 | // success case - no errors in HTTP response body |
| 352 | callback(err, body, response) |
| 353 | } |
| 354 | |
| 355 | req.on('response', function (res) { |
| 356 | response = res |
no outgoing calls
no test coverage detected
searching dependent graphs…