Permalink
Browse files

Correct yet another silly mistake from last round

  • Loading branch information...
1 parent ab3a997 commit 6fbdbcc9726c7328a0d5a5ca24d80bf1257198a1 @tedeh committed Sep 3, 2012
Showing with 9 additions and 5 deletions.
  1. +9 −5 lib/utils.js
View
@@ -118,21 +118,25 @@ Utils.httpRequestWrapper = function(server, options) {
options = Utils.merge(server.options, options || {});
// 405 method not allowed if not POST
- if(!Utils.isMethod(req, 'POST')) return error('Method not allowed', 405, { 'allow': 'POST' });
+ if(!Utils.isMethod(req, 'POST')) return respondError('Method not allowed', 405, { 'allow': 'POST' });
// 415 unsupported media type if content-type is not correct
- if(!Utils.isContentType(req, 'application/json')) return error('Unsupported media type', 415);
+ if(!Utils.isContentType(req, 'application/json')) return respondError('Unsupported media type', 415);
Utils.parseBody(req, options.reviver, function(err, request) {
// parsing failed, 500 server error
- if(err) return error(err, 500);
+ if(err) return respondError(err, 500);
server.call(request, function(error, success) {
var response = error || success;
if(response) {
var body = '';
// stringifies JSON
- try { body = JSON.stringify(response, options.replacer); } catch(err) { return error(err, 400); }
+ try {
+ body = JSON.stringify(response, options.replacer);
+ } catch(err) {
+ return respondError(err, 400);
+ }
var headers = {
"content-length": Buffer.byteLength(body, options.encoding),
"content-type": "application/json"
@@ -150,7 +154,7 @@ Utils.httpRequestWrapper = function(server, options) {
});
// ends the request with an error code
- function error(err, code, headers) {
+ function respondError(err, code, headers) {
res.writeHead(code, headers || {});
res.end(String(err));
}

0 comments on commit 6fbdbcc

Please sign in to comment.