Derive API Error Class from AAF Response (future)
772379
public Error getError(AuthzTrans trans, Future<?> fp) {
//		try {
			String text = fp.body();
			Error err = new Error();
			err.setMessageId(Integer.toString(fp.code()));
			if(text==null || text.length()==0) {
				err.setText("**No Message**");
			} else {
				err.setText(fp.body());
			}
			return err;
//		} catch (APIException e) {
//			Error err = new Error();
//			err.setMessageId(Integer.toString(fp.code()));
//			err.setText("Could not obtain response from AAF Message: " + e.getMessage());
//			return err;
//		}
	}
801500
def _process_async_error(self, resp_body, error_class):
        
        def _fmt_error(err):
            # Remove the cumbersome Java-esque message
            details = err.get("details", "").replace("\n", " ")
            if not details:
                details = err.get("message", "")
            return "%s (%s)" % (details, err.get("code", ""))

        error = resp_body.get("error", "")
        if "failedItems" in error:
            # Multi-error response
            faults = error.get("failedItems", {}).get("faults", [])
            msgs = [_fmt_error(fault) for fault in faults]
            msg = "\n".join(msgs)
        else:
            msg = _fmt_error(error)
        raise error_class(msg)
789416
function errorJSON (err) {
  var res = {}
  Object.getOwnPropertyNames(err).forEach(function (key) {
    res[key] = err[key]
  }, err)
  return res
}
84863
def from_response(response):
        """"""
        if response.code:
            return ERRORS[response.code](response)
        else:
            return Error(response)
1183607
def _get_error_message(self, response):
        """"""

        error_message = 'An error occurred processing your request.'
        try:
            content = response.json()
            # {"errors":[{"code":34,"message":"Sorry,
            # that page does not exist"}]}
            error_message = content['errors'][0]['message']
        except TypeError:
            error_message = content['errors']
        except ValueError:
            # bad json data from Twitter for an error
            pass
        except (KeyError, IndexError):
            # missing data so fallback to default message
            pass

        return error_message
1084446
def responsify(error):
    """"""
    assert str(type(error).__name__) == 'Error'
    if error.error in code_to_class:
        e = code_to_class[error.error](error.error_description)
        if error.error_id:
            e.error_id = error.error_id
        if error.user_message:
            e.user_message = error.user_message
        return e.http_reply()
    elif isinstance(error, PyMacaronException):
        return error.http_reply()
    else:
        return PyMacaronException("Caught un-mapped error: %s" % error).http_reply()
1052795
def _get_error_message(response):
    """"""
    try:
        data = response.json()
        if "error_description" in data:
            return data['error_description']
        if "error" in data:
            return data['error']
    except Exception:
        pass

    return "Unknown error"
695896
function _buildError(url, status, method, response) {
    var errorData = response || {};

    errorData.status = status;
    errorData.url = url;
    errorData.method = method;

    return errorData;
  }
132100
function transformAjvErrors(errors = []) {
  if (errors === null) {
    return [];
  }

  return errors.map(e => {
    const { dataPath, keyword, message, params, schemaPath } = e;
    let property = `${dataPath}`;

    // put data in expected format
    return {
      name: keyword,
      property,
      message,
      params, // specific to ajv
      stack: `${property} ${message}`.trim(),
      schemaPath,
    };
  });
}
1154128
def _raise_error_from_response(data):
    """"""
    # Check the meta-data for why this request failed
    meta = data.get('meta')
    if meta:
        # Account for foursquare conflicts
        # see: https://developer.foursquare.com/overview/responses
        if meta.get('code') in (200, 409): return data
        exc = error_types.get(meta.get('errorType'))
        if exc:
            raise exc(meta.get('errorDetail'))
        else:
            _log_and_raise_exception('Unknown error. meta', meta)
    else:
        _log_and_raise_exception('Response format invalid, missing meta property. data', data)
420178
private static ApiException createSyntheticErrorForRpcFailure(Throwable overallRequestError) {
    if (overallRequestError instanceof ApiException) {
      ApiException requestApiException = (ApiException) overallRequestError;

      return ApiExceptionFactory.createException(
          "Didn't receive a result for this mutation entry",
          overallRequestError,
          requestApiException.getStatusCode(),
          requestApiException.isRetryable());
    }

    return ApiExceptionFactory.createException(
        "Didn't receive a result for this mutation entry",
        overallRequestError,
        LOCAL_UNKNOWN_STATUS,
        false);
  }
812649
def _adapt_response(self, response):
        """"""
        if 'application/json' in response.headers['content-type']:
            body = response.json()
            status = response.status_code

            if body.get('error'):
                return self._simple_response_to_error_adapter(status, body)

        raise UnknownHttpError(response)
604488
def from_grpc_error(rpc_exc):
    
    if isinstance(rpc_exc, grpc.Call):
        return from_grpc_status(
            rpc_exc.code(), rpc_exc.details(), errors=(rpc_exc,), response=rpc_exc
        )
    else:
        return GoogleAPICallError(str(rpc_exc), errors=(rpc_exc,), response=rpc_exc)
930364
def from_requests_error(cls, err):
        
        import requests
        if isinstance(err, requests.HTTPError):
            status_code = err.response.status_code
            return HTTP_ERRORS.get(status_code, cls)(error=err, response=err.response)
        else:
            return cls(error=err)
1065405
function ForecastIoAPIError(url, statusCode, body) {
  this.response = {
    statusCode: statusCode,
    body: body
  };
  this.message = this._formatErrorMessage(body);
  this.name = "ForecastIoAPIError";
  Error.call(this);
  Error.captureStackTrace(this, arguments.callee);
  this.request = "GET " + url;
}
437316
function wrapError(spec, parsePayload) {
  return async function errorHandler(ctx, next) {
    try {
      await parsePayload(ctx, next);
    } catch (err) {
      captureError(ctx, 'type', err);
      if (spec.validate.continueOnError) {
        return await next();
      } else {
        return ctx.throw(err);
      }
    }
  };
}
658125
def _get_unknown_error_response(self, request, exc):
        

        logging.getLogger('devil').error(
            'while doing %s on %s with [%s], devil caught: %s' % (
                request.method, request.path_info, str(request.GET), str(exc)), exc_info=True)

        if settings.DEBUG:
            raise
        else:
            return HttpResponse(status=codes.INTERNAL_SERVER_ERROR[1])