Skip to content

Commit 0a7735f

Browse files
authored
Merge pull request #9 from archr/master
Fix unhandled 'error' event
2 parents ab297ce + 50f7b5e commit 0a7735f

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/algorithmia.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ AlgorithmiaClient = (function() {
100100
});
101101
return res;
102102
});
103+
httpRequest.on('error', function(err) {
104+
var body;
105+
body = {
106+
error: {
107+
message: err.message
108+
}
109+
};
110+
if (callback) {
111+
callback(body, 500);
112+
}
113+
});
103114
if (options.method !== 'HEAD') {
104115
httpRequest.write(data);
105116
}

lib/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ File = (function(superClass) {
5050
};
5151
innerCb = function(response, status) {
5252
var data, err;
53-
err = typeof response === 'object' && (response != null ? response.error : void 0) ? response.error : null;
53+
err = (typeof response === 'object' && (response != null ? response.error : void 0)) ? response.error : null;
5454
data = err === null ? response : null;
5555
return callback(err, data);
5656
};

src/algorithmia.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ class AlgorithmiaClient
8888
return
8989
res
9090
)
91+
httpRequest.on 'error', (err) ->
92+
body = error: { message: err.message }
93+
94+
if callback
95+
callback body, 500
96+
return
9197
if options.method != 'HEAD'
9298
httpRequest.write data
9399
httpRequest.end()

0 commit comments

Comments
 (0)