from http://nodejs.org/api/http.html#http_http_request_options_callback:
If any error is encountered during the request (be that with DNS
resolution, TCP level errors, or actual HTTP parse errors) an 'error' event
is emitted on the returned request object.
read: anything what results in invalid HTTP process will emit an 'error'.
Am Dienstag, 27. November 2012 15:20:42 UTC+1 schrieb GinnyD:
>
> I am currently using the http module to perform a POST operation to a
> remote API call and I'm trying to figure out the best way to handle error
> situations where things don't quite go as planned. I thought I could use
> the error event emitter but I have a situation where the server returns a
> 500 http status code but my code in the error event emitter never fires.
> My question is what will cause the error event emitter to fire? Is a http
> return code of 500 enough or is it looking for something else in the
> response from the call? The snippet of the node code in question is listed
> below. The res.statusCode shows a value of 500, but the console.log within
> the error emitter never fires off. This is occuring on version 0.8.11.
> Any guidance would be appreciated.
>
> Ginny
>
>
> *var post_data = querystring.stringify(data);*
>
> *
> *
>
> *// An object of options to indicate where to post to*
>
> *var post_options = {*
>
> * host: host_url,*
>
> * port: port_num,*
>
> * path: url_path,*
>
> * method: 'POST',*
>
> * headers: {*
>
> * 'Content-Type': 'application/x-www-form-urlencoded',*
>
> * 'Content-Length': post_data.length*
>
> * }*
>
> *};*
>
> *
> *
>
> *var req = http.request(post_options, function(res) {*
>
> * console.log('STATUS: ' + res.statusCode);*
>
> * console.log('HEADERS: ' + JSON.stringify(res.headers));*
>
> * res.setEncoding('utf8');*
>
> * res.on('data', function (chunk) {*
>
> * console.log('BODY: ' + chunk);*
>
> * });*
>
> *});*
>
> *
> *
>
> *req.on('error', function(e) {*
>
> * console.log('problem with request: ' + e.message);*
>
> *});*
>
> *
> *
>
> *req.write(post_data);*
>
> *req.end();*
>
>
>
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en