private function parseJson($json)
    {
        $data = @json_decode($json, true);
        if (null === $data) {
            throw new RuntimeException('JSON parsing failed: ' . json_last_error_msg());
        }

        if (!array_key_exists('response', $data)
            || !array_key_exists('success', $data)
            || !$data['success']
        ) {
            // Default exception.
            $excClass = RuntimeException::class;
            $excMessage = 'Invalid server response: ' . $json;
            if (array_key_exists('error', $data)) {
                $excClass = WebApiClientException::class;
                if (array_key_exists('type', $data['error'])) {
                    $className = __NAMESPACE__ . '\\Exception\\' . $data['error']['type'];
                    if (class_exists($className)) {
                        $excClass = $className;
                    }
                }
                if (array_key_exists('message', $data['error'])) {
                    $excMessage = $data['error']['message'];
                }
            }
            $this->getLogger()->error($excMessage);
            throw new $excClass($excMessage);
        }

        return $data['response'];
    }
private function parseJson($json)
    {
        $data = @json_decode($json, true);
        if (null === $data) {
            throw new RuntimeException('JSON parsing failed: ' . json_last_error_msg());
        }

        if (!array_key_exists('response', $data)
            || !array_key_exists('success', $data)
            || !$data['success']
        ) {
            // Default exception.
            $excClass = RuntimeException::class;
            $excMessage = 'Invalid server response: ' . $json;
            if (array_key_exists('error', $data)) {
                $excClass = WebApiClientException::class;
                if (array_key_exists('type', $data['error'])) {
                    $className = __NAMESPACE__ . '\\Exception\\' . $data['error']['type'];
                    if (class_exists($className)) {
                        $excClass = $className;
                    }
                }
                if (array_key_exists('message', $data['error'])) {
                    $excMessage = $data['error']['message'];
                }
            }
            $this->getLogger()->error($excMessage);
            throw new $excClass($excMessage);
        }

        return $data['response'];
    }
private function parseJson ( $ json ) { $ data = @ json_decode ( $ json , true ) ; if ( null === $ data ) { throw new RuntimeException ( 'JSON parsing failed: ' . json_last_error_msg ( ) ) ; } if ( ! array_key_exists ( 'response' , $ data ) || ! array_key_exists ( 'success' , $ data ) || ! $ data [ 'success' ] ) { // Default exception. $ excClass = RuntimeException :: class ; $ excMessage = 'Invalid server response: ' . $ json ; if ( array_key_exists ( 'error' , $ data ) ) { $ excClass = WebApiClientException :: class ; if ( array_key_exists ( 'type' , $ data [ 'error' ] ) ) { $ className = __NAMESPACE__ . '\\Exception\\' . $ data [ 'error' ] [ 'type' ] ; if ( class_exists ( $ className ) ) { $ excClass = $ className ; } } if ( array_key_exists ( 'message' , $ data [ 'error' ] ) ) { $ excMessage = $ data [ 'error' ] [ 'message' ] ; } } $ this -> getLogger ( ) -> error ( $ excMessage ) ; throw new $ excClass ( $ excMessage ) ; } return $ data [ 'response' ] ; }
Parse JSON response.

@param string $json Server JSON response.

@return array|string

@throws \Comindware\Tracker\API\Exception\RuntimeException In case of non-API errors.
@throws \Comindware\Tracker\API\Exception\WebApiClientException Ore one of descendants.
Parse JSON response .