Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/request / src / deps / toPrettyError.ts
Size: Mime:
/**
 * @todo rewrite this, has side effects
 */
export function toPrettyError(obj: Error | Response) {
  // attempt to use better and human-friendly error messages
  if (typeof obj.body === 'object' && typeof obj.body.message === 'string') {
    obj.prettyError = new Error(obj.body.message)
  } else if (
    !Array.isArray(obj.body) &&
    // attempt to utilize Stripe-inspired error messages
    typeof obj.body.error === 'object'
  ) {
    if (obj.body.error.message) {
      obj.prettyError = new Error(obj.body.error.message)
    }
    if (obj.body.error.stack) {
      obj.prettyError.stack = obj.body.error.stack
    }
    if (obj.body.error.code) {
      obj.prettyError.code = obj.body.error.code
    }
    if (obj.body.error.param) {
      obj.prettyError.param = obj.body.error.param
    }
  }
}