
function getUserErrorMessage (body) {
  const keys = ['errorID', 'error']
  if (body && body.errorID === 'UserError') {
    const err = Object.keys(body)
      .filter(key => !keys.includes(key))
      .reduce((obj, key) => {
        obj[key] = body[key]
        return obj
      }, {})
    return JSON.stringify(err)
  }
  return ''
}
function getErrorMessage (error) {
  return (error.body && error.body.error)
    ? `${error.body.error} ${getUserErrorMessage(error.body)}`
    : (error.error && error.error.message)
        ? error.error.message
        : error
}

module.exports = { getErrorMessage }
