lesstif / php-jira-rest-client

PHP classes interact Jira with the REST API.
Other
510 stars 263 forks source link

Store Jira error response into JiraException #372

Closed mu1f407 closed 3 years ago

mu1f407 commented 3 years ago

Hi, this PR adds storing of Jira response into JiraException in case of failed request. You can than easily read it in catch block and display errors to user.

Currently it is possible to retrieve response only from exception message using regexp which is more like a workaround.

Example of usage:

try {
    // some operation which throws JiraException
} catch (\JiraRestApi\JiraException $e) {
    $response = $e->getResponse();
    if ($response) {
        // request finished with status code >= 400
        $response = json_decode($response);
        $jiraErrorMessages = $response->errorMessages;
        $jiraErrors = $response->errors;
    } else {
        // request failed without response (possibly network error)
    }
}