2017-06-05 21:59:08 +00:00
|
|
|
'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) {
|
2017-06-06 23:13:15 +00:00
|
|
|
super('NotLoggedInError', msg, data);
|
2017-06-05 21:59:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChangedError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('ChangedError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NotFoundError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
2018-03-24 22:55:50 +00:00
|
|
|
super('NotFoundError', msg || 'Not Found', data);
|
|
|
|
this.status = 404;
|
2017-06-05 21:59:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 23:13:15 +00:00
|
|
|
class LoopDetectedError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('LoopDetectedError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 00:14:14 +00:00
|
|
|
class DuplicitNameError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('DuplicitNameError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
2017-06-08 22:23:03 +00:00
|
|
|
|
2017-06-30 14:11:02 +00:00
|
|
|
class DuplicitEmailError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('DuplicitEmailError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 06:51:30 +00:00
|
|
|
class DuplicitKeyError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('DuplicitKeyError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-08 13:48:34 +00:00
|
|
|
class IncorrectPasswordError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('IncorrectPasswordError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-09 21:16:47 +00:00
|
|
|
class InvalidTokenError extends InteroperableError {
|
2017-07-08 13:48:34 +00:00
|
|
|
constructor(msg, data) {
|
2017-07-09 21:16:47 +00:00
|
|
|
super('InvalidTokenError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DependencyNotFoundError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
2017-09-17 14:36:23 +00:00
|
|
|
super('DependencyNotFoundError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NamespaceNotFoundError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('NamespaceNotFoundError', msg, data);
|
2017-07-08 13:48:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-26 19:42:05 +00:00
|
|
|
class PermissionDeniedError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
2018-03-24 22:55:50 +00:00
|
|
|
super('PermissionDeniedError', msg || 'Permission Denied', data);
|
2017-07-27 14:11:22 +00:00
|
|
|
this.status = 403;
|
2017-07-26 19:42:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 20:44:35 +00:00
|
|
|
class InvalidConfirmationForSubscriptionError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('InvalidConfirmationForSubscriptionError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class InvalidConfirmationForAddressChangeError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('InvalidConfirmationForAddressChangeError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class InvalidConfirmationForUnsubscriptionError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('InvalidConfirmationForUnsubscriptionError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 17:05:22 +00:00
|
|
|
class DependencyPresentError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('DependencyPresentError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-26 09:46:12 +00:00
|
|
|
class InvalidStateError extends InteroperableError {
|
|
|
|
constructor(msg, data) {
|
|
|
|
super('InvalidStateError', msg, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 17:05:22 +00:00
|
|
|
|
2017-06-05 21:59:08 +00:00
|
|
|
const errorTypes = {
|
|
|
|
InteroperableError,
|
|
|
|
NotLoggedInError,
|
|
|
|
ChangedError,
|
2017-06-06 23:13:15 +00:00
|
|
|
NotFoundError,
|
2017-06-08 22:23:03 +00:00
|
|
|
LoopDetectedError,
|
2017-06-30 14:11:02 +00:00
|
|
|
DuplicitNameError,
|
2017-07-08 13:48:34 +00:00
|
|
|
DuplicitEmailError,
|
2017-08-11 06:51:30 +00:00
|
|
|
DuplicitKeyError,
|
2017-07-08 13:48:34 +00:00
|
|
|
IncorrectPasswordError,
|
2017-07-09 21:16:47 +00:00
|
|
|
InvalidTokenError,
|
2017-07-26 19:42:05 +00:00
|
|
|
DependencyNotFoundError,
|
2017-09-17 14:36:23 +00:00
|
|
|
NamespaceNotFoundError,
|
2017-12-10 20:44:35 +00:00
|
|
|
PermissionDeniedError,
|
|
|
|
InvalidConfirmationForSubscriptionError,
|
|
|
|
InvalidConfirmationForAddressChangeError,
|
2018-04-02 17:05:22 +00:00
|
|
|
InvalidConfirmationForUnsubscriptionError,
|
2018-08-26 09:46:12 +00:00
|
|
|
DependencyPresentError,
|
|
|
|
InvalidStateError
|
2017-06-05 21:59:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function deserialize(errorObj) {
|
|
|
|
if (errorObj.type) {
|
2017-06-06 23:13:15 +00:00
|
|
|
const ctor = errorTypes[errorObj.type];
|
|
|
|
if (ctor) {
|
|
|
|
return new ctor(errorObj.message, errorObj.data);
|
|
|
|
} else {
|
|
|
|
console.log('Warning unknown type of interoperable error: ' + errorObj.type);
|
|
|
|
}
|
2017-06-05 21:59:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Object.assign({}, errorTypes, {
|
|
|
|
deserialize
|
|
|
|
});
|