mailtrain/shared/interoperable-errors.js
Tomas Bures 5e4c86f626 Seems that hierarchical error handling works..
TreeTable component seems to work too.
Edit is half-way through. Create / delete are TBD.
2017-06-05 23:59:08 +02:00

44 lines
No EOL
924 B
JavaScript

'use strict';
class InteroperableError extends Error {
constructor(type, msg, data) {
super(msg);
this.type = type;
this.data = data;
}
}
class NotLoggedInError extends InteroperableError {
constructor(msg, data) {
super('NotLoggedIn', msg, data);
}
}
class ChangedError extends InteroperableError {
constructor(msg, data) {
super('ChangedError', msg, data);
}
}
class NotFoundError extends InteroperableError {
constructor(msg, data) {
super('NotFoundError', msg, data);
}
}
const errorTypes = {
InteroperableError,
NotLoggedInError,
ChangedError,
NotFoundError
};
function deserialize(errorObj) {
if (errorObj.type) {
return new errorTypes[errorObj.type](errorObj.message, errorObj.data)
}
}
module.exports = Object.assign({}, errorTypes, {
deserialize
});