danwrong/restler — Issue #47: Any request resulting in the error throws Uncaught exception
Author: amarchen
Created: 2011-11-16 19:11:02+00:00
State: open

Any request resulting in the error code from the server side to client running node.js 0.6.0 and restler results in the following (or similar stack) trace:

```
node restler_test.js
The "sys" module is now called "util". It should have a similar interface.

events.js:50
throw new Error("Uncaught, unspecified 'error' event.");
^
Error: Uncaught, unspecified 'error' event.
at EventEmitter.emit (events.js:50:15)
at EventEmitter._respond (/Users/artem/.node_libraries/restler/lib/restler.js:127:12)
at EventEmitter._fireEvents (/Users/artem/.node_libraries/restler/lib/restler.js:131:52)
at /Users/artem/.node_libraries/restler/lib/restler.js:115:19
at IncomingMessage. (/Users/artem/.node_libraries/restler/lib/restler.js:208:5)
at IncomingMessage. (/Users/artem/.node_libraries/restler/lib/restler.js:200:49)
at IncomingMessage. (/Users/artem/.node_libraries/restler/lib/restler.js:113:32)
at IncomingMessage.emit (events.js:88:20)
at HTTPParser.onMessageComplete (http.js:137:23)
at Socket.ondata (http.js:1125:24)
```

Investigation showed that the problem is with the event name and is probably similar to (or same as) https://github.com/LearnBoost/socket.io/issues/476

For example changing
```
_fireEvents: function(body, response) {
if (parseInt(response.statusCode) >= 400) this._respond('error', body, response);
```
to
```
_fireEvents: function(body, response) {
if (parseInt(response.statusCode) >= 400) this._respond('restlererror', body, response);
```
Makes everything work again, but of course event is incorrect then