smarterror/ts/index.ts

34 lines
915 B
TypeScript
Raw Normal View History

import * as plugins from './smarterror.plugins';
2017-06-09 12:59:36 +00:00
import { BaseError, fullStack } from 'make-error-cause';
export const seperatorText = `\n\nThe following exception was the direct cause of the above exception:\n\n`;
export class SmartError extends BaseError {
name = 'SmartError';
constructor(errorMessageArg: string, errorCause?) {
super(errorMessageArg, errorCause);
}
get fullStack() {
return fullStack(this);
}
get cleanFullStack() {
let fullCleanStack = plugins.cleanStack(this.stack);
let errorPointer = this as BaseError;
while (errorPointer.cause) {
fullCleanStack += seperatorText;
if (errorPointer.cause.stack) {
fullCleanStack += plugins.cleanStack(errorPointer.cause.stack);
} else {
fullCleanStack += errorPointer.cause.message;
}
errorPointer = errorPointer.cause as BaseError;
}
return fullCleanStack;
2017-06-09 12:59:36 +00:00
}
}