@spiralup/jfl-parser
Version:
Parser for JHipster Form definition Language
50 lines (45 loc) • 1.06 kB
JavaScript
/**
* This constant is where all the error cases go.
* No need to assign anything to the keys, the following loop will take care of
* that.
*/
const EXCEPTIONS = {
Assertion: null,
FileNotFound: null,
IllegalArgument: null,
IllegalAssociation: null,
IllegalName: null,
InvalidObject: null,
MalformedAssociation: null,
NoSQLModeling: null,
NullPointer: null,
UndeclaredEntity: null,
UnsupportedOperation: null,
WrongAssociation: null,
WrongFile: null,
WrongDir: null,
WrongType: null,
WrongValidation: null
};
/*
for (const key in EXCEPTIONS) {
if (EXCEPTIONS.hasOwnProperty(key)) {
EXCEPTIONS[key] = key;
}
}
*/
Object.keys(EXCEPTIONS).forEach(key => {
EXCEPTIONS[key] = key;
});
module.exports = {
exceptions: EXCEPTIONS,
buildException
};
function buildException(name, message) {
const exception = {
name: name ? `${name}Exception` : 'Exception',
message: message || ''
};
exception.prototype = new Error();
return exception;
}