Permalink
Browse files

Took out console.logs left in executable, made some other small changes

  • Loading branch information...
1 parent d3f4d44 commit 42dfd2a0ddb10db1fbc3820a57e50de039cba32d @larzconwell larzconwell committed Oct 2, 2012
Showing with 31 additions and 24 deletions.
  1. +0 −2 bin/cli.js
  2. +1 −1 lib/base_controller.js
  3. +30 −21 lib/response/errors.js
View
2 bin/cli.js
@@ -191,9 +191,7 @@ if (cmds.length) {
cmd += ' --quiet';
}
- console.log(cmd);
cmd = cmd.split(' ');
- console.log(cmd);
var jake = require('jake');
jake.run.apply(jake, cmd);
}
View
2 lib/base_controller.js
@@ -511,7 +511,7 @@ controller.BaseController.prototype = new (function () {
@param {Object} err The error to use as the basis for the response.
*/
this.completed = true;
- geddy.errors.respond(this.response, err);
+ geddy.errors.respond(err, this.response);
};
this.transfer = function (action) {
View
51 lib/response/errors.js
@@ -15,59 +15,68 @@
* limitations under the License.
*
*/
-var response = require('./index');
+var response = require('./index')
+ , errors;
-var errors = new function () {
+errors = new function () {
+
+ var self = this
+ , errorType
+ , errorConstructor
+ , createConstructor;
- var _this = this;
this.errorTypes = {
- 400: 'Bad Request',
- 401: 'Unauthorized',
- 403: 'Forbidden',
- 404: 'Not Found',
- 405: 'Method Not Allowed',
- 406: 'Not Acceptable',
- 500: 'Internal Server Error'
+ 400: 'Bad Request'
+ , 401: 'Unauthorized'
+ , 403: 'Forbidden'
+ , 404: 'Not Found'
+ , 405: 'Method Not Allowed'
+ , 406: 'Not Acceptable'
+ , 500: 'Internal Server Error'
};
- var errorType;
- var errorConstructor;
- var createConstructor = function (code, errorType) {
+ createConstructor = function (code, errorType) {
errorConstructor = function (message) {
this.statusCode = code;
this.statusText = errorType;
this.message = message || errorType;
+
Error.captureStackTrace(this);
}
errorConstructor.prototype = new Error();
+
return errorConstructor;
};
+
for (var code in this.errorTypes) {
// Strip spaces
errorType = this.errorTypes[code].replace(/ /g, '');
+
this[errorType + 'Error'] = createConstructor(code, errorType);
}
// For repetitively redundant name
this.InternalServerError = this.InternalServerErrorError;
- this.respond = function (resp, e) {
+ this.respond = function (err, res) {
// The no-error error ... whoa, meta!
- if (!e) {
+ if (!err) {
throw new Error('No error to respond with.');
}
- var r = new response.Response(resp);
- var code = e.statusCode || 500;
- var msg = '';
+ var r = new response.Response(res)
+ , code = err.statusCode || 500
+ , msg = '';
+
if (geddy.config.detailedErrors) {
- msg = e.stack || e.message || String(e);
+ msg = err.stack || err.message || String(err);
msg = msg.replace(/\n/g, '<br/>');
}
- msg = '<h3>Error: ' + code + ' ' + _this.errorTypes[code] + '</h3>' + msg;
+
+ msg = '<h3>Error: ' + code + ' ' + self.errorTypes[code] + '</h3>' + msg;
r.send(msg, code, {'Content-Type': 'text/html'});
};
}();
-for (var p in errors) { exports[p] = errors[p]; }
+module.exports = errors;

0 comments on commit 42dfd2a

Please sign in to comment.