response event was it thanks!
So what i eventually want to do is resturn a stream. On that stream i want
to munge together the http and application errors. Like this:
```
function changes (uri) {
var downstream = Stream.PassThrough()
request(uri)
.on('error', function (er) {
downstream.emit('error', er)
})
.on('response', function (res) {
if (res.statusCode >= 400)
res.on('data', function (data) {
downstream.emit('error', JSON.parse(data))
})
else
res.pipe(downstream)
})
return downstream
}
var c = changes(process.argv[2])
.on('error', function (er) {
console.log(er)
})
```
Whats the general consensus on doing this? I think its kinda wierd since
the errors come from different scopes, but at the same time I think it has
an application.
On Wednesday, May 29, 2013 1:29:52 AM UTC-7, greelgorke wrote:
>
> an HTTP 500 or 404 is not an error regarding HTTP so there is no need to
> emit an error on that. the http request havent caused an error. a HTTP 500
> (0r 4XX) indicates an error-state on the application level, that is
> abstract to the http layer.
>
> so request emits the 'response' event, here you can intercept the http
> non-ok states:
>
> ```
> var request = require('request')
>
> var req = request(process.argv[2])
> .on('error', function (er) {
> console.log('error')
> console.log(er)
> })
> .on('end', function () {
> console.log('end')
> })
> .on('response', function(res){
> if(res.statusCode >= 400){
> console.error('error: ' + res.statusCode)
> req.pipe(process.stderr)
> }else{
> req.pipe(process.stdout)
> }
> })
>
> ```
>
> Am Dienstag, 28. Mai 2013 21:51:16 UTC+2 schrieb Stephen Bartell:
>>
>> In general, If the connection to a server is successful, but the server
>> sends back an error message and sets the status code to an error state, I
>> want this response to be emitted as an `error` event on the stream.
>>
>> To be more specific, I want a streaming interface to a Couchdb changes
>> feed and I want errors from Couchdb to be emitted as 'error'. Right now,
>> if I create a stream to a couchdb changes feed and something goes wrong
>> inside couchdb , like the database doesnt exist or the authentication is
>> incorrect, an error will not be emitted. The response will be emitted as
>> data and the status code on the response will be the only indication that
>> the request failed.
>>
>> Heres some code and responses to clarify all this:
>>
>> Heres the program, index.js.
>> ```
>> var request = require('request')
>>
>> var req = request(process.argv[2])
>> .on('error', function (er) {
>> console.log('error')
>> console.log(er)
>> })
>> .on('end', function () {
>> console.log('end')
>> })
>> .pipe(process.stdout)
>> ```
>>
>> Requesting a changes feed where the couchdb port is wrong. This error
>> makes sense.
>> ```
>> $ node index.js http://localhost:598/test
>> error
>> { [Error: connect ECONNREFUSED]
>> code: 'ECONNREFUSED',
>> errno: 'ECONNREFUSED',
>> syscall: 'connect' }
>> ```
>>
>> Requesting a changes feed where an error occurs in couchdb. The path to
>> couchdb is correct, but the database does not exist. The request ends
>> "successfully".
>> ```
>> $ node index.js http://localhost:5984/tes
>> {"error":"not_found","reason":"no_db_file"}
>> end
>> ```
>>
>> What I want is something like this:
>> ```
>> $ node index.js http://localhost:5984/tes
>> error
>> { [Error: not_found],
>> reason: "no_db_file" }
>> ```
>>
>>
>>
--
--
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
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.