Error handling in the PHP client library

I am using the PHP client library, and I can’t seem to figure out how to handle errors.

For instance, when I use Postman to get a task with an invalid task gid, it will return an error message.

But, when I use the PHP library and call $client->tasks->getTask($task_gid, array(‘opt_pretty’ => ‘true’)) with an invalid task gid, it will simply break the code of the page. Nothing below that snippet will render. I’ve been unable to find a way to catch the error and fail gracefully.

Are there any php code examples of how to handle this?
Thanks!

Some problem… I resolwed it with chfnging SDK Client in vendor/asana/asana/src/Asana/Client.php

public function request($method, $path, $options)
{
    $options = Client::array_merge_recursive_distinct($this->options, $options);

    $requestOptions = $this->parseRequestOptions($options);
    $uri = $options['base_url'] . $path;
    $retryCount = 0;

    while (true) {
        try {
            $response = $this->dispatcher->request($method, $uri, $requestOptions);

            if (!array_key_exists('headers', $options)) {
                $options['headers'] = array();
            }
            $this->logAsanaChangeHeaders($options['headers'], $response->headers->toArray());

            Errors\AsanaError::handleErrorResponse($response);

            if ($options['full_payload']) {
                return $response->body;
            } else {
                return $response->body->data;
            }
        } catch (RetryableAsanaError $e) {
            if ($retryCount < $options['max_retries']) {
                $this->handleRetryableError($e, $retryCount);
                $retryCount++;
            } else {
                // Handle RetryableAsanaError
                $this->logException($e);
            }
        } catch (Exception $e) {
            // Handle other Exception
            $this->logException($e);
        }
    }
}

private function logException($e)
{
    // Your code to log exception.

    die('Exception!');
}

Some problem… I resolved it with changing SDK in vendor/asana/asana/src/Asana/Client.php

public function request($method, $path, $options)
{
$options = Client::array_merge_recursive_distinct($this->options, $options);

$requestOptions = $this->parseRequestOptions($options);
$uri = $options['base_url'] . $path;
$retryCount = 0;

while (true) {
    try {
        $response = $this->dispatcher->request($method, $uri, $requestOptions);

        if (!array_key_exists('headers', $options)) {
            $options['headers'] = array();
        }
        $this->logAsanaChangeHeaders($options['headers'], $response->headers->toArray());

        Errors\AsanaError::handleErrorResponse($response);

        if ($options['full_payload']) {
            return $response->body;
        } else {
            return $response->body->data;
        }
    } catch (RetryableAsanaError $e) {
        if ($retryCount < $options['max_retries']) {
            $this->handleRetryableError($e, $retryCount);
            $retryCount++;
        } else {
            // Handle RetryableAsanaError
            $this->logException($e);
        }
    } catch (Exception $e) {
        // Handle other Exception
        $this->logException($e);
    }
}

}

private function logException($e)
{
// Your code to log exception.

die('Exception!');

}

(post deleted by author)