summaryrefslogtreecommitdiff
path: root/bin/wiki/ImportarDesdeURL/node_modules/whoops/lib/create-extend-error.js
blob: ee191c44127af87eed1a323d06318b245a24f863 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict'

const cleanStack = require('clean-stack')
const mimicFn = require('mimic-fn')

const addErrorProps = require('./add-error-props')
const {isString} = require('./helpers')

function createExtendError (ErrorClass, classProps) {
  function ExtendError (props) {
    const error = new ErrorClass()
    const errorProps = isString(props) ? {message: props} : props
    addErrorProps(error, classProps, errorProps)

    error.stack = cleanStack(error.stack)
    return error
  }

  ExtendError.prototype = ErrorClass.prototype
  mimicFn(ExtendError, ErrorClass)

  return ExtendError
}

module.exports = createExtendError