@param string $apiName
@param array  $data
@param string $answerFormat
@param int    $try_number Try number of getting answer from api

@return array|object
@throws ConnectionException
@throws \WebSocket\BadOpcodeException
511716
public function doRequest($apiName, array $data, $answerFormat = self::ANSWER_FORMAT_ARRAY, $try_number = 1)
    {
        $requestId = $this->getNextId();
        $requestData = [
            'jsonrpc' => '2.0',
            'id'     => $requestId,
            'method' => 'call',
            'params' => [
                $apiName,
                $data['method'],
                $data['params']
            ]
        ];
        try {
            $connection = $this->getConnection();
            $connection->send(json_encode($requestData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
            $answerRaw = $connection->receive();
            $answer = json_decode($answerRaw, self::ANSWER_FORMAT_ARRAY === $answerFormat);

            if (
                (self::ANSWER_FORMAT_ARRAY === $answerFormat && isset($answer['error']))
                || (self::ANSWER_FORMAT_OBJECT === $answerFormat && isset($answer->error))
            ) {
                throw new ConnectionException('got error in answer: ' . $answer['error']['code'] . ' ' . $answer['error']['message']);
            }
            //check that answer has the same id or id from previous tries, else it is answer from other request
            if (self::ANSWER_FORMAT_ARRAY === $answerFormat) {
                $answerId = $answer['id'];
            } elseif (self::ANSWER_FORMAT_OBJECT === $answerFormat) {
                $answerId = $answer->id;
            }
            if ($requestId - $answerId > ($try_number - 1)) {
                throw new ConnectionException('got answer from old request');
            }


        } catch (ConnectionException $e) {

            if ($try_number < $this->maxNumberOfTriesToCallApi) {
                //if got WS Exception, try to get answer again
                $answer = $this->doRequest($apiName, $data, $answerFormat, $try_number + 1);
            } elseif ($this->isExistReserveNodeUrl()) {
                //if got WS Exception after few ties, connect to reserve node
                $this->connectToReserveNode();
                $answer = $this->doRequest($apiName, $data, $answerFormat);
            } else {
                //if nothing helps
                throw $e;
            }
        }

        return $answer;
    }
90707
public static function formatJump($code, $msg = '', $url = '', $data = '', $wait = 3)
    {
        return array(
            'code' => $code,
            'msg' => $msg,
            'url' => $url,
            'data' => $data,
            'wait' => $wait
        );
    }
222260
public <T> ApiResponse<T> execute(Call call) throws ApiException {
        return execute(call, null);
    }
827507
private function responseHandler($requestMethod, $requestPath, array $clientResponse)
    {
        $statusCode = (int) $clientResponse[0];
        $responseString = (string) $clientResponse[1];

        try {
            $responseData = Json::decode($responseString);
            $this->validateClientResponse($requestMethod, $requestPath, $statusCode, $responseData);

            if (400 <= $statusCode) {
                // either we sent an incorrect request, or there is a server error
                throw new HttpClientException(sprintf('[%d] %s "%s/%s": %s', $statusCode, $requestMethod, $this->baseUri, $requestPath, $responseData['error']));
            }

            // the request was correct, and there was not a server error
            if ($responseData[$requestPath]['ok']) {
                // our request was handled correctly
                if (!\array_key_exists('data', $responseData[$requestPath])) {
                    return null;
                }

                return $responseData[$requestPath]['data'];
            }

            // our request was not handled correctly, something went wrong...
            throw new ApiException($responseData[$requestPath]['error']);
        } catch (JsonException $e) {
            // unable to parse the JSON
            throw new HttpClientException(sprintf('[%d] %s "%s/%s": %s', $statusCode, $requestMethod, $this->baseUri, $requestPath, $e->getMessage()));
        }
    }
339071
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $error = new ErrorMessageValue([
            'code' => $data['errorCode'],
            'message' => isset($data['errorMessage']) ? $data['errorMessage'] : null,
            'description' => isset($data['errorDescription']) ? $data['errorDescription'] : null,
            'details' => isset($data['errorDetails']) ? $data['errorDetails'] : null,
            'trace' => isset($data['trace']) ? $data['trace'] : null,
            'file' => isset($data['file']) ? $data['file'] : null,
            'line' => isset($data['line']) ? $data['line'] : null,
        ]);

        // So client behaves closer to api, return relevant exceptions on status codes that maps to them
        if (isset($this->errorCodeMapping[$data['errorCode']])) {
            $exceptionClass = $this->errorCodeMapping[$data['errorCode']];
            return new $exceptionClass($data['errorDescription'], $data['errorCode'], new ServerException($error));
        }

        return $error;
    }
655251
private function doSend($method, array $data, $token = null)
    {
        try {
            $data['token'] = $token ?: $this->token;

            $this->eventDispatcher->dispatch(self::EVENT_REQUEST, new RequestEvent($data));

            $request = $this->createRequest($method, $data);

            /** @var ResponseInterface $response */
            $response = $this->client->send($request);
        } catch (\Exception $e) {
            throw new SlackException('Failed to send data to the Slack API', null, $e);
        }

        try {
            $responseData = json_decode($response->getBody()->getContents(), true);
            if (!is_array($responseData)) {
                throw new \Exception(sprintf(
                    'Expected JSON-decoded response data to be of type "array", got "%s"',
                    gettype($responseData)
                ));
            }

            $this->eventDispatcher->dispatch(self::EVENT_RESPONSE, new ResponseEvent($responseData));

            return $responseData;
        } catch (\Exception $e) {
            throw new SlackException('Failed to process response from the Slack API', null, $e);
        }
    }
1184864
def try_call(self, client_data=None, api_data=None, aux_data=None, *args, **kwargs):
        
        try:
            return self.call(client_data, api_data, aux_data, *args, **kwargs)
        except Exception as e:
            self.last_exception = RequestFailed(cause=e)
        return None
714479
private function parseExceptionForErrorMessages(Exception $e)
    {
        if (! $e instanceof BadResponseException) {
            throw new ApiException($e->getMessage());
        }

        $response = $e->getResponse();
        Psr7\rewind_body($response);
        $responseBody = $response->getBody()->getContents();
        $decodedResponseBody = json_decode($responseBody, true);

        if (! is_null($decodedResponseBody) && isset($decodedResponseBody['error']['message']['value'])) {
            $errorMessage = $decodedResponseBody['error']['message']['value'];
        } else {
            $errorMessage = $responseBody;
        }

        throw new ApiException('Error ' . $response->getStatusCode() . ': ' . $errorMessage, $response->getStatusCode());
    }
900613
protected function restore_question_attempt_step_worker($data, $nameprefix) {
        global $DB;

        $data = (object)$data;
        $oldid = $data->id;

        // Pull out the response data.
        $response = array();
        if (!empty($data->{$nameprefix . 'response'}[$nameprefix . 'variable'])) {
            foreach ($data->{$nameprefix . 'response'}[$nameprefix . 'variable'] as $variable) {
                $response[$variable['name']] = $variable['value'];
            }
        }
        unset($data->response);

        $data->questionattemptid = $this->get_new_parentid($nameprefix . 'question_attempt');
        $data->userid      = $this->get_mappingid('user', $data->userid);

        // Everything ready, insert and create mapping (needed by question_sessions)
        $newitemid = $DB->insert_record('question_attempt_steps', $data);
        $this->set_mapping('question_attempt_step', $oldid, $newitemid, true);

        // Now process the response data.
        $response = $this->questions_recode_response_data(
                $this->qtypes[$data->questionattemptid],
                $this->newquestionids[$data->questionattemptid],
                $data->sequencenumber, $response);

        foreach ($response as $name => $value) {
            $row = new stdClass();
            $row->attemptstepid = $newitemid;
            $row->name = $name;
            $row->value = $value;
            $DB->insert_record('question_attempt_step_data', $row, false);
        }
    }
1185574
public ApiResponse<ApiSuccessResponse> ackRecentMissedCallsWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = ackRecentMissedCallsValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<ApiSuccessResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
63551
protected function doRequest($method, $apiMethod, array $data = [])
    {
        $url = $this->config['endpoint'] . $apiMethod;
        $data = $this->mergeData($this->createAuthData(), $data);

        $response = $this->getGuzzleClient()->request($method, $url, ['json' => $data]);
        $responseContent = \GuzzleHttp\json_decode($response->getBody());

        if (!property_exists($responseContent, 'success') || !$responseContent->success) {
            throw new InvalidRequestException($method, $url, $data, $response);
        }

        return $responseContent;
    }
27758
public function create($api, array $data)
    {
        return $this->checkException($this->callHttpMethod($this->normalizeUri($api), Request::METHOD_POST, $data));
    }
301401
public function getResult()
  {
    $arrayData = $this->decode(
      $this->getResponse()
        ->getBody()
        ->getContents()
    );
    if (is_array($arrayData) && count($arrayData)) {
      $singleItem = reset($arrayData);
    } else {
      throw new ResponseDecodeException('Response has bad format.');
    }

    return new Contact($singleItem);
  }
85893
final protected function createApiException(ResponseInterface $response, $data, $code = null, $message = null)
    {
        $e = new ApiException(get_class($this).' #'.$code.': '.$message);
        $e->setResponse($response);
        $e->setData($data);
        $e->setErrorCode($code);
        $e->setErrorMessage($message);

        return $e;
    }
235716
public function decodeList(&$apiData)
    {
        $resObj = json_decode($apiData);
        if (isset($resObj->error)) {
            $msg = "Error " . $resObj->error->code . " " . $resObj->error->message;
            if (isset($resObj->error->errors[0])) {
                $msg .= " : " . $resObj->error->errors[0]->reason;
            }

            throw new \Exception($msg);
        } else {
            $this->page_info = [
                'resultsPerPage' => $resObj->pageInfo->resultsPerPage,
                'totalResults' => $resObj->pageInfo->totalResults,
                'kind' => $resObj->kind,
                'etag' => $resObj->etag,
                'prevPageToken' => null,
                'nextPageToken' => null,
            ];

            if (isset($resObj->prevPageToken)) {
                $this->page_info['prevPageToken'] = $resObj->prevPageToken;
            }

            if (isset($resObj->nextPageToken)) {
                $this->page_info['nextPageToken'] = $resObj->nextPageToken;
            }

            $itemsArray = $resObj->items;
            if (!is_array($itemsArray) || count($itemsArray) == 0) {
                return false;
            } else {
                return $itemsArray;
            }
        }
    }
263436
public ApiResponse<GetSubResponse> getSubWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = getSubValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<GetSubResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
833490
public com.squareup.okhttp.Call getPingAsync(final ApiCallback<String> callback) throws ApiException {

        com.squareup.okhttp.Call call = getPingValidateBeforeCall(callback);
        Type localVarReturnType = new TypeToken<String>() {
        }.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }