rxstack/rxstack

View on GitHub
packages/exceptions/src/transform-to-exception.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import {Exception} from './exception';

/**
 * Transform an error to exception
 *
 * @param e
 * @returns {Exception}
 */
export function transformToException(e: any): Exception {
  const name = e.name;
  const originalError = e;
  if (!(e instanceof Exception)) {
    e = new Exception(e.message);
    e.name = name;
    e.originalError = originalError;
    e.stack = require('stack-trace').parse(originalError);
  }
  return e;
}