summaryrefslogtreecommitdiffstats
path: root/lib/utils/error.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/error.js')
-rw-r--r--lib/utils/error.js53
1 files changed, 52 insertions, 1 deletions
diff --git a/lib/utils/error.js b/lib/utils/error.js
index 66e20db..4ccf83d 100644
--- a/lib/utils/error.js
+++ b/lib/utils/error.js
@@ -1,4 +1,6 @@
var _ = require('lodash');
+var TypedError = require('error/typed');
+var WrappedError = require('error/wrapped');
// Enforce as an Error object, and cleanup message
function enforce(err) {
@@ -8,6 +10,55 @@ function enforce(err) {
return err;
}
+// Random error wrappers during parsing/generation
+var ParsingError = WrappedError({
+ message: 'Parsing Error: {origMessage}',
+ type: 'server.parsing-failed'
+});
+var GenerationError = WrappedError({
+ message: 'Generation Error: {origMessage}',
+ type: 'server.parsing-failed'
+});
+
+// Error when output generator does not exists
+var GeneratorNotFoundError = TypedError({
+ type: 'server.404',
+ message: 'Generator "{generator}" does not exists',
+ generator: null
+});
+
+// A file does not exists
+var FileNotFoundError = TypedError({
+ type: 'server.404',
+ message: 'No "{filename}" file (or is ignored)',
+ filename: null
+});
+
+// A file is outside the scope
+var FileOutOfScopeError = TypedError({
+ type: 'server.404',
+ message: '"{filename}" not in "{root}"',
+ filename: null,
+ root: null,
+ code: 'EACCESS'
+});
+
+// Error for nunjucks templates
+var TemplateError = WrappedError({
+ message: 'Error compiling template "{filename}": {origMessage}',
+ type: 'client.template-failed',
+ filename: null
+});
+
module.exports = {
- enforce: enforce
+ enforce: enforce,
+
+ ParsingError: ParsingError,
+ GenerationError: GenerationError,
+
+ FileNotFoundError: FileNotFoundError,
+ FileOutOfScopeError: FileOutOfScopeError,
+
+ GeneratorNotFoundError: GeneratorNotFoundError,
+ TemplateError: TemplateError
};