@intuitionrobotics/ts-common
Version:
99 lines • 3.81 kB
JavaScript
;
/*
* ts-common is the basic building blocks of our typescript projects
*
* Copyright (C) 2020 Intuition Robotics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Created by IR on 3/16/17.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AssertionException = exports.WhoCallthisException = exports.DontCallthisException = exports.ThisShouldNotHappenException = exports.NotImplementedYetException = exports.MUSTNeverHappenException = exports.ImplementationMissingException = exports.BadImplementationException = exports.Exception = exports.CustomException = void 0;
exports.isErrorOfType = isErrorOfType;
function isErrorOfType(e, _exceptionType) {
if (!(e instanceof Error))
return;
const _e = e;
if (_e.isInstanceOf && _e.isInstanceOf(_exceptionType))
return e;
}
class CustomException extends Error {
constructor(exceptionType, message, cause) {
super(message);
this.message = message;
this.stack = (new Error(message)).stack;
this.cause = cause instanceof Error ? cause : new Error(JSON.stringify(cause || message));
this.exceptionType = exceptionType.name;
this.isInstanceOf = (_exceptionType) => {
return this.exceptionType === _exceptionType.name;
};
}
}
exports.CustomException = CustomException;
class Exception extends CustomException {
constructor(message, cause) {
super(Exception, message, cause);
}
}
exports.Exception = Exception;
class BadImplementationException extends CustomException {
constructor(message, cause) {
super(BadImplementationException, message, cause);
}
}
exports.BadImplementationException = BadImplementationException;
class ImplementationMissingException extends CustomException {
constructor(message, cause) {
super(ImplementationMissingException, message, cause);
}
}
exports.ImplementationMissingException = ImplementationMissingException;
class MUSTNeverHappenException extends CustomException {
constructor(message, cause) {
super(MUSTNeverHappenException, message, cause);
}
}
exports.MUSTNeverHappenException = MUSTNeverHappenException;
class NotImplementedYetException extends CustomException {
constructor(message, cause) {
super(NotImplementedYetException, message, cause);
}
}
exports.NotImplementedYetException = NotImplementedYetException;
class ThisShouldNotHappenException extends CustomException {
constructor(message, cause) {
super(ThisShouldNotHappenException, message, cause);
}
}
exports.ThisShouldNotHappenException = ThisShouldNotHappenException;
class DontCallthisException extends CustomException {
constructor(message, cause) {
super(DontCallthisException, message, cause);
}
}
exports.DontCallthisException = DontCallthisException;
class WhoCallthisException extends CustomException {
constructor(message, cause) {
super(WhoCallthisException, message, cause);
}
}
exports.WhoCallthisException = WhoCallthisException;
class AssertionException extends CustomException {
constructor(message, cause) {
super(AssertionException, message, cause);
}
}
exports.AssertionException = AssertionException;
//# sourceMappingURL=exceptions.js.map