Handle an error response from the SABnzbd API
351021
def _handle_error(self, data, params):
        """"""
        error = data.get('error', 'API call failed')
        mode = params.get('mode')
        raise SabnzbdApiException(error, mode=mode)
996812
protected void handleConfigureResponseFailure(RaftMemberContext member, ConfigureRequest request, Throwable error) {
    // Log the failed attempt to contact the member.
    failAttempt(member, request, error);
  }
1260847
public <T extends BullhornEntity> CrudResponse handleHttpFourAndFiveHundredErrors(CrudResponse response,
            HttpStatusCodeException error, Integer id) {
        response.setChangedEntityId(id);
        Message message = new Message();
        message.setDetailMessage(error.getResponseBodyAsString());
        message.setSeverity("ERROR");
        message.setType(error.getStatusCode().toString());
        response.addOneMessage(message);
        response.setErrorCode(error.getStatusCode().toString());
        response.setErrorMessage(error.getResponseBodyAsString());
        return response;

    }
604499
def _handle_satosa_authentication_error(self, error):
        
        context = Context()
        context.state = error.state
        frontend = self.module_router.frontend_routing(context)
        return frontend.handle_backend_error(error)
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();

    }
715690
function extractError(resp) {
    var codes = {
      304: 'NotModified',
      403: 'Forbidden',
      400: 'BadRequest',
      404: 'NotFound'
    };

    var req = resp.request;
    var code = resp.httpResponse.statusCode;
    var body = resp.httpResponse.body || '';

    var headers = resp.httpResponse.headers || {};
    var region = headers['x-amz-bucket-region'] || null;
    var bucket = req.params.Bucket || null;
    var bucketRegionCache = req.service.bucketRegionCache;
    if (region && bucket && region !== bucketRegionCache[bucket]) {
      bucketRegionCache[bucket] = region;
    }

    var cachedRegion;
    if (codes[code] && body.length === 0) {
      if (bucket && !region) {
        cachedRegion = bucketRegionCache[bucket] || null;
        if (cachedRegion !== req.httpRequest.region) {
          region = cachedRegion;
        }
      }
      resp.error = AWS.util.error(new Error(), {
        code: codes[code],
        message: null,
        region: region
      });
    } else {
      var data = new AWS.XML.Parser().parse(body.toString());

      if (data.Region && !region) {
        region = data.Region;
        if (bucket && region !== bucketRegionCache[bucket]) {
          bucketRegionCache[bucket] = region;
        }
      } else if (bucket && !region && !data.Region) {
        cachedRegion = bucketRegionCache[bucket] || null;
        if (cachedRegion !== req.httpRequest.region) {
          region = cachedRegion;
        }
      }

      resp.error = AWS.util.error(new Error(), {
        code: data.Code || code,
        message: data.Message || null,
        region: region
      });
    }
    req.service.extractRequestIds(resp);
  }
817945
def _handle_api_result(result: Optional[Dict[str, Any]]) -> Any:
    
    if isinstance(result, dict):
        if result.get('status') == 'failed':
            raise ActionFailed(retcode=result.get('retcode'))
        return result.get('data')
473572
private String failureProcessing(BackupAgentResponse response) throws BackupExecuteException
   {
      try
      {
         String result =
                  "\nFailure :\n" + "\tstatus code : " + response.getStatus() + "\n" + "\tmessage      : "
                           + new String(response.getResponseData(), "UTF-8") + "\n\n";

         return result;
      }
      catch (UnsupportedEncodingException e)
      {
         throw new BackupExecuteException("Can not encoded the responce : " + e.getMessage(), e);
      }
   }
776345
def errorhandle(self, resp):            
        """"""
        if self.format == 'json':
            parsed = xmltodict.parse(resp)
            errors = parsed[self.RESPONSE_TOKEN][self.ERROR_TOKEN]
            # Create list of errors if more than one error response is given
            if type(errors) is list and len(errors) > 1:
                messages = ", ".join([" ".join(["{}: {}".format(k,v) for k, v in e.items()]) for e in errors])
            else:
                overlimit = any('transaction limit' in msg.lower() for msg in errors.values())
                if overlimit:
                    raise APILimitExceeded("This API key has used up its daily quota of calls.")
                else:    
                    messages = " ".join(["{}: {}".format(k,v) for k, v in errors.items()])    
        elif self.format == 'xml':
            import xml.etree.ElementTree as ET
            errors = ET.fromstring(resp).findall(self.ERROR_TOKEN)
            messages = ", ".join(err.find('msg').text for err in errors)
        else:
            raise ValueError("Invalid API response format specified: {}." % self.format)        
        
        raise BustimeError("API returned: {}".format(messages))
232756
function handleCallback(callback, err, httpResponse, body) {

    if(err){
        return callback(err);
    }

    //
    // API returns error
    //
    if( body.status !== 'OK' ){
        return callback(new Error(body.comment));
    }

    return callback(null, body.result);
}
659762
function handle(err, results) {
      if (err) {
        errors.push(err);
      }

      // add all responses to the array
      (Array.isArray(results) ? results : [results]).forEach(function each(value) {
        if (value && memcached.namespace.length) {
          var ns_key = Object.keys(value)[0]
            , newvalue = {};

          newvalue[ns_key.replace(memcached.namespace, '')] = value[ns_key];
          Utils.merge(responses, newvalue);
        } else {
          Utils.merge(responses, value);
        }
      });

      if (!--calls){
          callback(errors.length ? errors : undefined, responses);
      }
    }
331757
public function handleApiError($rbody, $rcode, $resp)
    {
        if (!is_object($resp) || !isset($resp->error)) {
            $msg = "Invalid response object from API: $rbody "
                ."(HTTP response code was $rcode)";
            throw new Error\Api($msg, $rcode, $rbody, $resp);
        }

        $error = $resp->error;
        $msg = isset($error->message) ? $error->message : null;
        $param = isset($error->param) ? $error->param : null;
        $code = isset($error->code) ? $error->code : null;

        switch ($rcode) {
            case 400:
                if ($code == 'rate_limit') {
                    throw new Error\RateLimit(
                        $msg, $param, $rcode, $rbody, $resp
                    );
                }
            case 404:
                throw new Error\InvalidRequest(
                    $msg, $param, $rcode, $rbody, $resp
                );
            case 401:
                throw new Error\Authentication($msg, $rcode, $rbody, $resp);
            case 402:
                throw new Error\Channel(
                    $msg, $code, $param, $rcode, $rbody, $resp
                );
            default:
                throw new Error\Api($msg, $rcode, $rbody, $resp);
        }
    }
534452
function processResponse(err, res, cb){
  if(!err) {
    if(Array.isArray(res.body)){
      res.body.forEach(function (body) {
        castRecordDateFields(body);
      });
    } else if (_.isObject(res.body)) {
      castRecordDateFields(res.body);
    }
  }
  cb();
}
342551
def _check_error_response(response, query):
        
        if "error" in response:
            http_error = ["HTTP request timed out.", "Pool queue is full"]
            geo_error = [
                "Page coordinates unknown.",
                "One of the parameters gscoord, gspage, gsbbox is required",
                "Invalid coordinate provided",
            ]
            err = response["error"]["info"]
            if err in http_error:
                raise HTTPTimeoutError(query)
            elif err in geo_error:
                raise MediaWikiGeoCoordError(err)
            else:
                raise MediaWikiException(err)
69068
def handle_error(self, error, response):
        
        query_params = {"error": error.error}

        query = urlencode(query_params)

        location = "%s?%s" % (self.client.redirect_uri, query)

        response.status_code = 302
        response.body = ""
        response.add_header("Location", location)

        return response
1310418
protected function handleErrorResponse(string $body, array $headers, int $status, string $url): void
    {
        switch ($status) {
            case 400:
            case 405:
                $returnArray = json_decode($body, true);
                throw new ApiSyntaxException($returnArray['message']);
            case 401:
            case 403:
                $returnArray = json_decode($body, true);
                $message = $returnArray['message'] ?? 'Invalid credentials';

                if (isset($returnArray['hint'])) {
                    $message .= ': ' . $returnArray['hint'];
                }

                throw new ApiAuthenticationException($message);
            case 410:
            case 404:
                throw new ApiNotFoundException($url);
                break;
            default:
                $returnArray = json_decode($body, true);
                throw new ApiGeneralException($this->generalExceptionMessage($returnArray ?? [], $headers));
        }
    }
924120
function handleError(res) {
  return function (err) {
    if (err.status && err.name !== 'NotFoundError') {
      // If we're in this block, the error has a defined `status` property and
      // the error should be directed out immediately
      sendDefaultResponseForCode(err.status, err.message, res);
    } else if (err.name === 'NotFoundError' ||
      err.message.indexOf('ENOENT') !== -1 ||
      err.message.indexOf('not found') !== -1) {
      notFound(err, res);
      // if the word "client" is ever in a message, it should be for the client.  We enforce that here.
    } else if (err.message.indexOf('Client') !== -1) {
      clientError(err, res);
    } else {
      serverError(err, res);
    }
  };
}