'use strict'

const _ = require('lodash')

module.exports = function createError (message, status) {
  let props
  let Constructor = Error

  if (_.isPlainObject(message)) {
    props = _.omit(message, 'message')

    if (message.constructor) {
      Constructor = props.constructor
    }

    message = message.message || 'Error'
  } else {
    props = {}
  }

  if (_.isPlainObject(status)) {
    Object.assign(props, status)
  } else if (typeof status === 'number') {
    props.status = status
  }

  const err = new Constructor(message)

  Object.assign(err, props)

  return err
}

'use strict'

const _ = require('lodash')

module.exports = function createError (message, status) {
  let props
  let ErrorConstructor = Error

  if (_.isPlainObject(message)) {
    props = _.omit(message, 'message')

    if (message.errorConstructor) {
      ErrorConstructor = props.errorConstructor
    }

    message = message.message || 'Error'
  } else {
    props = {}
  }

  if (_.isPlainObject(status)) {
    Object.assign(props, status)
  } else if (typeof status === 'number') {
    props.status = status
  }

  const err = new ErrorConstructor(message)

  Object.assign(err, props)

  return err
}

Rename constructor option to avoid collision with prototype constructor
Rename constructor option to avoid collision with prototype constructor
