Catch an error
This commit is contained in:
parent
7b2d0f549d
commit
3acc2eb17d
|
@ -26,6 +26,7 @@ DocumentHandler.prototype.handlePost = function(request, response) {
|
||||||
var key = '123';
|
var key = '123';
|
||||||
request.on('data', function(data) {
|
request.on('data', function(data) {
|
||||||
if (!DocumentHandler.documents[key]) {
|
if (!DocumentHandler.documents[key]) {
|
||||||
|
response.writeHead(200, { 'content-type': 'application/json' });
|
||||||
DocumentHandler.documents[key] = '';
|
DocumentHandler.documents[key] = '';
|
||||||
}
|
}
|
||||||
DocumentHandler.documents[key] += data.toString();
|
DocumentHandler.documents[key] += data.toString();
|
||||||
|
@ -35,7 +36,9 @@ DocumentHandler.prototype.handlePost = function(request, response) {
|
||||||
response.end(JSON.stringify({ key: key }));
|
response.end(JSON.stringify({ key: key }));
|
||||||
});
|
});
|
||||||
request.on('error', function(error) {
|
request.on('error', function(error) {
|
||||||
// TODO handle error
|
winston.error('connection error: ' + error.message);
|
||||||
|
response.writeHead(500, { 'content-type': 'application/json' });
|
||||||
|
response.end(JSON.stringify({ message: 'connection error' }));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue