/**
 * Base class for custom errors.
 *
 * Copyright (C) 2015 Martin Poelstra
 * License: MIT
 */ /**
 * Base class for custom errors, which preserves stack and
 * has correct prototype chain.
 */ export default class BaseError extends Error { public stack ! : string ; constructor ( name , message ) { super ( message ) ; let fixStack = false ; if ( this . constructor !== new . target ) { if ( ( < any > Object ) . setPrototypeOf ) { ( < any > Object ) . setPrototypeOf ( this , new . target . prototype ) ; } fixStack = true ; } if ( ! ( "stack" in this ) ) { fixStack = true ; } this . name = name ; if ( fixStack ) { if ( Error . captureStackTrace ) { Error . captureStackTrace ( this , new . target ) ; } else { const error = new Error ( message ) ; error . name = name ; try { throw error ; } catch ( error ) { this . stack = error . stack || String ( error ) ; } } } } }