mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
30b4eb07f7
- This is a first pass at getting a more logical structure. The focus is on moving from admin/frontend to client/server. - The location of the databases is highly important, this isn't expected to change again In the future - client/assets should probably become public/ - more stuff should be shared (helpers etc) - cleanup some confusion around tpl and views
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
var _ = require('underscore'),
|
|
errors;
|
|
|
|
/**
|
|
* Basic error handling helpers
|
|
*/
|
|
errors = {
|
|
throwError: function (err) {
|
|
if (!err) {
|
|
err = new Error("An error occurred");
|
|
}
|
|
|
|
if (_.isString(err)) {
|
|
throw new Error(err);
|
|
}
|
|
|
|
throw err;
|
|
},
|
|
|
|
logError: function (err) {
|
|
err = err || "Unknown";
|
|
// TODO: Logging framework hookup
|
|
console.log("Error occurred: ", err.message || err, err.stack || "");
|
|
},
|
|
|
|
logAndThrowError: function (err) {
|
|
this.logError(err);
|
|
|
|
this.throwError(err);
|
|
},
|
|
|
|
logErrorWithMessage: function (msg) {
|
|
var self = this;
|
|
|
|
return function () {
|
|
self.logError(msg);
|
|
};
|
|
},
|
|
|
|
logErrorWithRedirect: function (msg, redirectTo, req, res) {
|
|
var self = this;
|
|
|
|
return function () {
|
|
self.logError(msg);
|
|
|
|
if (_.isFunction(res.redirect)) {
|
|
res.redirect(redirectTo);
|
|
}
|
|
};
|
|
}
|
|
};
|
|
|
|
// Ensure our 'this' context in the functions
|
|
_.bindAll(errors, "throwError", "logError", "logAndThrowError", "logErrorWithMessage", "logErrorWithRedirect");
|
|
|
|
module.exports = errors; |