True if o is an instance of a swagger Error model or a flask Response of
    an error model
324861
def is_error(o):
    """"""
    if hasattr(o, 'error') and hasattr(o, 'error_description') and hasattr(o, 'status'):
        return True
    return False
1064019
def _get_model_instance(model_cls, data):
        
        if not isinstance(data, (model_cls, dict)):
            raise TypeError('{0} is not valid type, instance of '
                            '{1} or dict required'.format(data, model_cls))
        return model_cls(**data) if isinstance(data, dict) else data
273014
function OAuthError(errorResponse, message) {
	this.name = "OAuthError";
	this.message = message || errorResponse.errorMessage;
	this.code = errorResponse.code;
	this.response = errorResponse;

	if (Error.captureStackTrace
		&& typeof Error.captureStackTrace === 'function') {
		Error.captureStackTrace(this, OAuthError);
	}
}
745530
def single_error_check(client, status)
      begin
        response_class = status[:response_class]
      rescue
        raise "no response_class found: #{status.inspect}" if !response_class
      end

      if status[:response_class] == "Error"
        return "#{status[:response_code]} - #{status[:message_text]}"
      elsif status[:response_class] == "Warning"
        Rews.log{|logger| logger.warn("#{status[:response_code]} - #{status[:message_text]}")}
      end
    end
967885
def result_or_error(response):
    
    data = response.json()
    result = data.get('result')
    if result is not None:
        return result
    raise exceptions.ApiError(response, data)
73242
def check_public_ok(func):
    

    def wrapper(request, *args, **kwargs):
        default_to_open = getattr(settings, 'DEFAULT_TO_OPEN_READ', False)
        database_name = kwargs.get('database_name', "")
        collection_name = kwargs.get('collection_name', "")
        if not default_to_open:
            if not database_name or not collection_name:
                return HttpResponse(unauthorized_json_response(),
                                    content_type="application/json")
            try:
                pub_read_api = PublicReadAPI.objects.get(
                    database_name=database_name, collection_name=collection_name)
            except PublicReadAPI.DoesNotExist:
                return HttpResponse(unauthorized_json_response(),
                                    content_type="application/json")

            # If search keys have been limited...
            if pub_read_api.search_keys:
                search_key_list = shlex.split(pub_read_api.search_keys)
                keys = []
                for k in request.GET.keys():

                    if k not in search_key_list:
                        message = "Search key %s is not allowed." % (k)

                        body = {"code": 400,
                                "message": k,
                                "errors": [message, ]}

                        return HttpResponse(json.dumps(body, indent=4, ),
                                            content_type="application/json")
        return func(request, *args, **kwargs)

    return update_wrapper(wrapper, func)
1300929
function(err, model) {
                    if (err) {
                        return _fn(err);
                    }
                    if (!model) {
                        return _fn('No model (' + name + ') returned from `adapter.registerModel`');
                    }
                    mycro.models[name] = model;
                    _fn();
                }
935662
def from_response(response):
        '''
        
        '''
        cls = PLAID_ERROR_TYPE_MAP.get(response['error_type'], PlaidError)
        return cls(response['error_message'],
                   response['error_type'],
                   response['error_code'],
                   response['display_message'],
                   response['request_id'],
                   response.get('causes'))
1214873
def skip_http_error(statuses):
    '''
    
    '''

    assert isinstance(statuses, tuple)

    def decorator(func):
        def wrapper(*args, **kwargs):
            try:
                return func(*args, **kwargs)
            except HTTPError as e:
                status_code = e.response.status_code
                if status_code in statuses:
                    log.warn(str(e))
                else:
                    raise
        return wrapper
    return decorator
282369
def build_api_error(response, blob=None):
    
    try:
        blob = blob or response.json()
    except json.JSONDecodeError:
        blob = {}
    error_list = blob.get('errors', None)
    error = (error_list[0] if error_list else {})
    if error:
        error_id = error.get('id', '')
        error_message = error.get('message', '')
    else:
        # In the case of an OAuth-specific error, the response data is the error
        # blob, and the keys are slightly different. See
        # https://developers.coinbase.com/api/v2#error-response
        error_id = blob.get('error')
        error_message = blob.get('error_description')
    error_class = (
        _error_id_to_class.get(error_id, None) or
        _status_code_to_class.get(response.status_code, APIError))
    return error_class(response, error_id, error_message, error_list)
38873
function responseErrorBuilder(err, res) {
  if (res && res.body && _.isObject(res.body) && res.body.error) {
    // pass through error obj from API
    return res.body;
  } else {
    // build custom error
    return {
      error: {
        code: err.status || CL_CONSTANTS.RES_UNKNOWN,
        message: (res ? res.text : null) || err.toString(),
      }
    };
  }
}
527372
def is_valid(data):
        
        return bool(data) and \
            isinstance(data, dict) and \
            bool(data.get("swagger")) and \
            isinstance(data.get('paths'), dict)
1320455
def make_json_error(error):
    
    message = extract_error_message(error)
    status_code = extract_status_code(error)
    context = extract_context(error)
    retryable = extract_retryable(error)
    headers = extract_headers(error)

    # Flask will not log user exception (fortunately), but will log an error
    # for exceptions that escape out of the application entirely (e.g. if the
    # error handler raises an error)
    error_logger.debug("Handling {} error: {}".format(
        status_code,
        message,
    ))

    # Serialize into JSON response
    response_data = {
        "code": status_code,
        "context": context,
        "message": message,
        "retryable": retryable,
    }
    # Don't pass in the error schema because it will suppress any extra fields
    return dump_response_data(None, response_data, status_code, headers)
1078954
def from_response(response, method, url):
    

    req_id = response.headers.get("x-openstack-request-id")
    # NOTE(hdd) true for older versions of nova and cinder
    if not req_id:
        req_id = response.headers.get("x-compute-request-id")
    kwargs = {
        "http_status": response.status_code,
        "response": response,
        "method": method,
        "url": url,
        "request_id": req_id,
    }
    if "retry-after" in response.headers:
        kwargs["retry_after"] = response.headers["retry-after"]

    content_type = response.headers.get("Content-Type", "")
    if content_type.startswith("application/json"):
        try:
            body = response.json()
        except ValueError:
            pass
        else:
            if isinstance(body, dict):
                error = body.get(list(body)[0])
                if isinstance(error, dict):
                    kwargs["message"] = (error.get("message") or
                                         error.get("faultstring"))
                    kwargs["details"] = (error.get("details") or
                                         six.text_type(body))
    elif content_type.startswith("text/"):
        kwargs["details"] = response.text

    try:
        cls = _code_map[response.status_code]
    except KeyError:
        if 500 <= response.status_code < 600:
            cls = HttpServerError
        elif 400 <= response.status_code < 500:
            cls = HTTPClientError
        else:
            cls = HttpError
    return cls(**kwargs)
1073747
def error_view(template_dir=None):
    
    if not template_dir:
        template_dir = "Pylot/Error"

    template_page = "%s/index.html" % template_dir

    class Error(Pylot):
        """
        Error Views
        """
        @classmethod
        def register(cls, app, **kwargs):
            super(cls, cls).register(app, **kwargs)

            @app.errorhandler(400)
            def error_400(error):
                return cls.index(error, 400)

            @app.errorhandler(401)
            def error_401(error):
                return cls.index(error, 401)

            @app.errorhandler(403)
            def error_403(error):
                return cls.index(error, 403)

            @app.errorhandler(404)
            def error_404(error):
                return cls.index(error, 404)

            @app.errorhandler(500)
            def error_500(error):
                return cls.index(error, 500)

            @app.errorhandler(503)
            def error_503(error):
                return cls.index(error, 503)

        @classmethod
        def index(cls, error, code):
            cls.meta_(title="Error %s" % code)

            return cls.render(error=error, view_template=template_page), code
    return Error
507171
def get_data_or_404(model, instance_id, kind=''):
    
    data = get_data(model, instance_id, kind)

    if not data:
        return abort(404)

    return data
760947
def is_middleware(func) -> bool:
    

    if inspect.isfunction(func):
        _check = func
        _name = func.__name__
    else:
        _check = func.__call__
        _name = func.__class__.__name__

    if not inspect.iscoroutinefunction(_check):
        raise UnknownMiddlewareException("Middleware {} should be async function".format(_name))

    args = list(inspect.signature(_check).parameters.keys())

    if set(args) - MIDDLEWARE_PARAMETER_BOUNDARY:
        raise UnknownMiddlewareException("Parameters of middleware {} "
                                         "must be in list ['app', 'request', 'response', 'next']".format(_name))

    return True