@param string $rbody A JSON string.
@param int $rcode
@param array $resp

@throws InvalidRequestError if the error is caused by the user.
@throws AuthenticationError if the error is caused by a lack of
permissions.
@throws ApiError otherwise.
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);
        }
    }
711587
public function build($rawRequestArgument): Request
    {
        if (empty($rawRequestArgument['context']) || !is_string($rawRequestArgument['context'])) {
            throw new Exception('tx_typoscriptrendering|context must not be empty and must be of type string!', 1403793452);
        }
        $rawRequest = @json_decode($rawRequestArgument['context'], true);
        if (null === $rawRequest) {
            throw new Exception('tx_typoscriptrendering|context must contain a valid json string!', 1466679262);
        }
        return new Request($rawRequest);
    }
811682
private void requestAuthorization(HttpServletResponse resp) throws IOException {

        // Authorisation is required for the requested action.
        resp.setHeader(CmsRequestUtil.HEADER_WWW_AUTHENTICATE, "Basic realm=\"" + BASIC_REALM + "\"");

        resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    }
809251
protected function response($respBody, $respHeaders, $respCode)
    {
        // Handle non successful HTTP status codes
        if ($respCode > 400) {
            $type = $respCode > 500 ? 'Internal error' : 'Request error';
            throw new GeneralException(
                'The request to NeverBounce was unsuccessful '
                . 'Try the request again, if this error persists'
                . ' let us know at support@neverbounce.com.'
                . "\n\n($type [status $respCode: $respBody])"
            );
        }

        // Check that the response type is expected
        $contentType = $respHeaders['content-type'];
        if ($this->acceptedType !== $contentType) {
            throw new GeneralException(
                'The request to NeverBounce was unsuccessful '
                . "Expected a response type of '{$this->acceptedType}' but "
                . "received a response type of '{$contentType}. "
                . 'Try the request again, if this error persists'
                . ' let us know at support@neverbounce.com.'
                . "\n\n(Unexpected Type [status $respCode: $respBody])"
            );
        }

        // Handle response based on Content-Type
        if ($this->acceptedType === 'application/json') {
            return $this->jsonResponse($respBody, $respCode);
        }

        return $this->decodedResponse = $respBody;
    }
959794
static function setRedirectData(M $m, $url, array $p = [], $forceGet = false) {$m->iiaSet(
		self::$REDIRECT_DATA, ['forceGet' => $forceGet, 'p' => $p, 'url' => $url]
	);}
1246185
def set_rcode(self, rcode):
        
        (value, evalue) = dns.rcode.to_flags(rcode)
        self.flags &= 0xFFF0
        self.flags |= value
        self.ednsflags &= 0x00FFFFFFL
        self.ednsflags |= evalue
        if self.ednsflags != 0 and self.edns < 0:
            self.edns = 0
391768
public function checkResponseSign($request, $signData, $resp, $respObject) {

		if (!$this->checkEmpty($this->alipayPublicKey) || !$this->checkEmpty($this->alipayrsaPublicKey)) {


			if ($signData == null || $this->checkEmpty($signData->sign) || $this->checkEmpty($signData->signSourceData)) {

				throw new Exception(" check sign Fail! The reason : signData is Empty");
			}


			// 获取结果sub_code
			$responseSubCode = $this->parserResponseSubCode($request, $resp, $respObject, $this->format);


			if (!$this->checkEmpty($responseSubCode) || ($this->checkEmpty($responseSubCode) && !$this->checkEmpty($signData->sign))) {

				$checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType);


				if (!$checkResult) {

					if (strpos($signData->signSourceData, "\\/") > 0) {

						$signData->signSourceData = str_replace("\\/", "/", $signData->signSourceData);

						$checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType);

						if (!$checkResult) {
							throw new Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]");
						}

					} else {

						throw new Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]");
					}

				}
			}


		}
	}
1120984
public function checkAuthorizeParams()
    {
        // Get required params
        $clientId = $this->server->getRequest()->query->get('client_id', null);
        if (is_null($clientId)) {
            throw new Exception\InvalidRequestException('client_id');
        }

        $redirectUri = $this->server->getRequest()->query->get('redirect_uri', null);
        if (is_null($redirectUri)) {
            throw new Exception\InvalidRequestException('redirect_uri');
        }

        // Validate client ID and redirect URI
        $client = $this->server->getClientStorage()->get(
            $clientId,
            null,
            $redirectUri,
            $this->getIdentifier()
        );

        if (($client instanceof ClientEntity) === false) {
            $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
            throw new Exception\InvalidClientException();
        }

        $state = $this->server->getRequest()->query->get('state', null);
        if ($this->server->stateParamRequired() === true && is_null($state)) {
            throw new Exception\InvalidRequestException('state', $redirectUri);
        }

        $responseType = $this->server->getRequest()->query->get('response_type', null);
        if (is_null($responseType)) {
            throw new Exception\InvalidRequestException('response_type', $redirectUri);
        }

        // Ensure response type is one that is recognised
        if (!in_array($responseType, $this->server->getResponseTypes())) {
            throw new Exception\UnsupportedResponseTypeException($responseType, $redirectUri);
        }

        // Validate any scopes that are in the request
        $scopeParam = $this->server->getRequest()->query->get('scope', '');
        $scopes = $this->validateScopes($scopeParam, $client, $redirectUri);

        return [
            'client'        => $client,
            'redirect_uri'  => $redirectUri,
            'state'         => $state,
            'response_type' => $responseType,
            'scopes'        => $scopes
        ];
    }
578441
function (err, body) {
          if (!err) {
            var val = body.GET
            if (val) {
              /*
              {
                "GET": "[resource]@[id]"
              }
              */
              val = val.split('@')
              // overwrite body
              body = {
                'resource': val[0],
                '_id': val[1]
              }

              // success, pass the object
              callback(null, body)
            } else {
              // Redis key not found
              body = {
                'status': 404,
                'error_code': -44,
                'message': 'Page not found, invalid slug or store ID'
              }
              var msg = body.message
              errorHandling(callback, msg, body)
            }
          } else {
            // just pass the error
            callback(err, body)
          }
        }
469100
private function runSingleRequest($request_method, $parameters) {

        try {

            $registered_method = $this->checkRequestSustainability($request_method);

            $selected_signature = $this->checkRequestConsistence($registered_method, $parameters);

            if ( is_array($parameters) ) $parameters = self::matchParameters($parameters, $registered_method, $selected_signature);

            $this->parameters->setParameters($parameters);

            $callback = $registered_method->getCallback();

            $attributes = $registered_method->getArguments();

            array_unshift($attributes, $this->parameters);

        } catch (RpcException $re) {

            throw $re;

        }

        set_error_handler(

            function($severity, $message, $file, $line) {

                $this->logger->error($message, array(
                    "FILE" => $file,
                    "LINE" => $line
                ));

                throw new RpcException('Internal error', -32603);

            }

        );

        try {

            // $return = call_user_func($callback, $this->parameters);
            $return = call_user_func_array($callback, $attributes);

        } catch (RpcException $re) {

            restore_error_handler();

            throw $re;

        } catch (Exception $e) {

            restore_error_handler();

            $this->logger->error($e->getMessage(), array(
                "FILE" => $e->getFile(),
                "LINE" => $e->getLine()
            ));

            throw new RpcException('Internal error', -32603);

        }

        restore_error_handler();

        return $return;

    }
438776
def jsonrpc_request(method, identifier, params=None):
    """"""
    return '{}\r\n'.format(json.dumps({
        'id': identifier,
        'method': method,
        'params': params or {},
        'jsonrpc': '2.0'
    })).encode()
1361421
function(server, callback) {
        var self = this, serverId;

        serverId = server instanceof rackspace.Server ? server.id : server;

        if (!server) {
            throw new Error('Server is a required argument.');
        }

        var requestOptions = {
            uri: '/servers/' + serverId,
            method: 'DELETE'
        };

        self.authorizedRequest(requestOptions, function(err, res, body) {
            if (err) {
                callback(err);
                return;
            }

            callback(err, res.statusCode === 204);
        });
    }
884573
function httpRedirect (url, code) {
    // default to 302 redirect code
    if (!code) {
        code = 302
    }
    // create new error
    var err = new Error('Redirect')
    err.code = code
    err.url = url
    // throw error which will be handled by application framework
    throw err
}
680798
protected function jsonError(\Exception $obj_error, $int_code)
    {
        $arr_response = [
            'code' => $int_code,
            'msg' => ($obj_error instanceof \ErrorException ? 'Internal Error' : 'Exception')
        ];
        $str_log_message = get_class($obj_error) . ': ' . $obj_error->getMessage();
        if($this->bol_expose_errors) {
            $arr_response['detail'] = $str_log_message;
        }
        if($int_code < 400 || $int_code > 505) {
            $int_code = 500;
        }
        $this->sendResponse($arr_response, $int_code);
        $this->getLogger()->error("[JAPI] [{$int_code}] Error: {$str_log_message}");
    }
91091
private function validateArray($value, string $errorDescription) : void
    {
        if (!is_array($value)) {
            throw new JsonRpcInvalidRequestException($value, $errorDescription);
        }
    }
663165
def _fill_request(self, request, rdata):
        """"""
        if not isinstance(rdata, dict):
            raise InvalidRequestError

        request['jsonrpc'] = self._get_jsonrpc(rdata)
        request['id'] = self._get_id(rdata)
        request['method'] = self._get_method(rdata)
        request['params'] = self._get_params(rdata)
408831
def validate_response(self, resp):
        
        ok, msg = self.contract.validate(self.returns, 
                                         self.returns.is_array, resp)
        if not ok:
            vals = (self.full_name, str(resp), msg)
            msg = "Function '%s' invalid response: '%s'. %s" % vals
            raise RpcException(ERR_INVALID_RESP, msg)