API error handling
769968
def on_api_error(self, error_status=None, message=None, event_origin=None):

        
        if message.meta["error"].find("Widget instance not found on server") > -1:
            # widget is missing on the other side, try to re-attach
            # then try again
            error_status["retry"] = True
            self.comm.attach_remote(
                self.id,
                self.remote_name,
                remote_name=self.name,
                **self.init_kwargs
            )
1303093
function (req, res) {
    var error = new errors.NotFound('Page Does Not Exist');
    if (req.accepts('html') && (req.url.indexOf('/api/') !== 0)) {
      this.renderErrorPage('404', error, req, res);
    } else {
      this.renderError(error, req, res);
    }
  }
165776
function throwStatusError(resp) {
  let err = new Error(resp.statusText || 'http error: ' + resp.status);
  err.type = resp.status;
  err.response = resp;
  err.url = resp.url;
  throw err;
}
73603
function _errorHandlers() {
  // middleware with an arity of 4 are considered
  // error handling middleware. When you next(err)
  // it will be passed through the defined middleware
  // in order, but ONLY those with an arity of 4, ignoring
  // regular middleware.
  app.use(function(err, req, res, next){
    logger.error(err);
    console.trace();
    if(req.accepts('html') || req.is('html')) {
      res.status(err.status || 500);
      res.render('500', { error: err });
      return;
    }
    res.send(err.status || 500, { error: err.message });
  });

  // our custom JSON 404 middleware. Since it's placed last
  // it will be the last middleware called, if all others
  // invoke next() and do not respond.
  app.use(function(req, res) {
    logger.error('Failed to locate:'+req.url);
    console.trace();
    if(req.accepts('html') || req.is('html')) {
      res.status(404);
      res.render('404', { url: req.url });
      return;
    }
    res.send(404, { error: "can't find the resource" });
  });
}
607480
def error_handler(f):
    """"""
    @wraps(f)
    def inner(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except ReceiverDoesNotExist:
            return jsonify(
                status=404,
                description='Receiver does not exists.'
            ), 404
        except InvalidPayload as e:
            return jsonify(
                status=415,
                description='Receiver does not support the'
                            ' content-type "%s".' % e.args[0]
            ), 415
        except WebhooksError:
            return jsonify(
                status=500,
                description='Internal server error'
            ), 500
    return inner
671103
function handleQueryError (err) {

        queryErrorCount++;

        // Something has gone terribly wrong. Break from loop.
        if (queryErrorCount > 1) {

            // Reset all filters.
            session.list.formData = {};

            // Notify the user that an error has occured.
            req.linz.notifications.push(linz.api.views.notification({
                text: 'One of the filters is repeatedly generating an error. All filters have been removed.',
                type: 'error'
            }));

            // Rerun the query at the last known working state.
            // eslint-disable-next-line no-use-before-define
            return getModelIndex();

        }

        // Reset the last known working state.
        session.list.formData = session.list.previous.formData;

        // If we're in development mode, return the error
        // so that the developers are aware of it and can fix it.
        if (isDevelopment) {
            return next(err);
        }

        // Notify the user that an error has occured.
        req.linz.notifications.push(linz.api.views.notification({
            text: 'An error has occured with one of the filters you added. It has been removed.',
            type: 'error'
        }));

        // Rerun the query at the last known working state.
        // eslint-disable-next-line no-use-before-define
        return getModelIndex();

    }
413702
def handle_error(response, body)
      unless [200, 201].include?(response.status)
        raise Passfort::Errors::RequestError.new([], response)
      end

      errors = body["errors"].is_a?(Array) ? body["errors"] : [body["errors"]]

      handle_response_error(errors, response) if errors.any?
    end
914468
def handle_errors(callback, parsed=None, out=sys.stderr):

    """"""

    try:
        if parsed:
            return callback(parsed)
        else:
            return callback()
    except DeploymentError as e:
        traceback.print_exc(file=out)
        print(e, file=out)
        if hasattr(e, 'value') and hasattr(e.value, 'args') and len(e.value.args) > 0 and \
                'open_sftp_client' in e.value.args[0]:
            print('Timeout', file=out)
            return TIMEOUT
        return DEPLOYMENT_ERROR
    except MalformedResponseError as e:
        traceback.print_exc(file=out)
        print(e, file=out)
        if 'Service Unavailable' in e.body:
            return SERVICE_UNAVAILABLE
        return MALFORMED_RESPONSE
    except SystemExit:
        pass
    except:
        traceback.print_exc(file=out)
        return EXCEPTION
347769
def _handle_api_error(self, error):
        
        status_code = error.response.status_code
        message = error.message

        if 403 == status_code:
            raise NewRelicInvalidApiKeyException(message)
        elif 404 == status_code:
            raise NewRelicUnknownApplicationException(message)
        elif 422 == status_code:
            raise NewRelicInvalidParameterException(message)
        else:
            raise NewRelicApiException(message)
1016727
function HTTPError(statusCode, data) {
  Error.call(this);
  Error.captureStackTrace(this, this.constructor);

  /**
   * Human-readable error name.
   *
   * @type {String}
   */
  this.name = http.STATUS_CODES[statusCode];

  /**
   * HTTP status code.
   *
   * @type {Number}
   */
  this.statusCode = statusCode;

  /**
   * Any additional data.
   *
   * @type {*}
   */
  this.data = data;

  if (data) {
    // Property of Error.
    this.message = JSON.stringify(data);
  }
}
608999
function onError(e) {
    if (!inBrowser) {
        return {};
    }

    let response = {};
    if (e.response) {
        response = e.response.data;
    }

    throw Object.assign({
        statusCode: 500,
        message: 'Request error'
    }, response);
}
860521
def _handle_http_errors(response):
    
    code = response.status_code
    if 200 <= code < 400:
        return response
    elif code in (403, 404):
        raise {403: _ObjectPermissionError,
               404: _ObjectNotFoundError}[code](response.reason)
    response.raise_for_status()
351021
def _handle_error(self, data, params):
        """"""
        error = data.get('error', 'API call failed')
        mode = params.get('mode')
        raise SabnzbdApiException(error, mode=mode)
366390
function apiError(err) {
	var f = testProbe ? testProbe : anomaly.anomaly
	f.apply(this, Array.prototype.slice.call(arguments))
}
268212
def _check_for_errors(response, json_response):
        
        status_code = response.status_code
        try:
            response.raise_for_status()
        except requests.HTTPError as why:
            raise ApiError(str(why), reply_code=status_code)
        if isinstance(json_response, dict) and 'error' in json_response:
            raise ApiError(json_response['error'], reply_code=status_code)
1281151
def handle_error(self):
        """"""
        if self.server.can_ignore_error(self):
            return
        if thread_local.status_code is None:
            msg("ERROR: Cannot send error status code! " +
                "Header already sent!\n{0}", traceback.format_exc())
        else:
            msg("ERROR: Error while processing request:\n{0}",
                traceback.format_exc())
            try:
                self.send_error(500, "Internal Error")
            except:  # nopep8
                if self.server.can_ignore_error(self):
                    return
                msg("ERROR: Cannot send error status code:\n{0}",
                    traceback.format_exc())
24803
function handleError(call, error) {
  var statusMetadata = new Metadata();
  var status = {
    code: constants.status.UNKNOWN,
    details: 'Unknown Error'
  };
  if (error.hasOwnProperty('message')) {
    status.details = error.message;
  }
  if (error.hasOwnProperty('code') && Number.isInteger(error.code)) {
    status.code = error.code;
    if (error.hasOwnProperty('details')) {
      status.details = error.details;
    }
  }
  if (error.hasOwnProperty('metadata')) {
    statusMetadata = error.metadata;
  }
  status.metadata = statusMetadata._getCoreRepresentation();
  var error_batch = {};
  if (!call.metadataSent) {
    error_batch[grpc.opType.SEND_INITIAL_METADATA] =
        (new Metadata())._getCoreRepresentation();
  }
  error_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = status;
  call.startBatch(error_batch, function(){});
}