Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to handle uncaught exception in http.get response
    primarykey
    data
    text
    <p>I have this code to pull down a news feed from a third party website using an API. Its setup to run every 5 seconds, and pull any news transactions that may occur. The problem seems to be when there is no new transactions that occur. </p> <p>By adding the process.on('uncaught exception', function(error){ console.log("hmph") }) the cron job is able to continue 5 seconds later, so I was tempted to leave it as is; however, I added console.log("hmph") to the and now I'm confused.</p> <p>The first time, the console will write hmph. 5 seconds later it will write hmph hmph</p> <p>and so on. I know I must be missing something, but I'm not quite sure what it is. I've tried in the else statement to do request.end() but the error still fires.</p> <p>Without the process.on('uncaught...') the error thrown is:</p> <blockquote> <p>events.js:71 throw arguments[1]; // Unhandled 'error' event ^ Error: Parse Error at Socket.socketOnData (http.js:1367:20) at TCP.onread (net.js:403:27)</p> </blockquote> <p>with the proccess.on('uncaught...') the console.log(error) is:</p> <blockquote> <p>{ [Error: Parse Error] bytesParsed: 161, code: 'HPE_INVALID_CONSTANT' }</p> </blockquote> <p>How do I properly handle this error?</p> <p>Abbreviated code:</p> <pre><code>var job = new cronJob('*/5 * * * * *', function(){ var request = http.get({ host: 'www.example.com', path: '/news_feed?apicode=myapicode', port: 80, headers: { 'accept-encoding': 'gzip' } }) request.on('response', function(response){ if (response.statusCode == 200){ // gunzip response, save response to mongodb } else { // here is where the error is occuring process.on('uncaughtException',function(error){ console.log(error); console.log("hmph"); } }); }, null, true); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload