chobie / jira-api-restclient

php JIRA REST API
MIT License
217 stars 123 forks source link

How to catch exceptions? #155

Closed benjivm closed 7 years ago

benjivm commented 7 years ago

The following isn't working:

    try {
            $walker = $this->walker();
            $walker->push($jql, $this->fields);
    } catch (\Exception $e) {
            return 'Nope!';
    }

I am still getting the Laravel error page:

UnauthorizedException in CurlClient.php line 141:
Unauthorized

I have also tried namespacing to the API, like this:

    try {
            $walker = $this->walker();
            $walker->push($jql, $this->fields);
    } catch (\chobie\Jira\Api\Exception $e) {
            return 'Nope!';
    }
aik099 commented 7 years ago

Creating the walker or calling push method on it doesn't make any API calls to JIRA. The first call is made, when you try to foreach($walker as $issue) { over issues.

So I guess you need to put try/catch around the foreach.

benjivm commented 7 years ago

@aik099 Thanks, that did the trick.

Would it make sense to create a way to check the session status via the API? I am not sure if that is even a part of JIRA's API, but something like $api->currentUser() that would return false if not logged in.

Thanks a lot for all your and @jpastoor work maintaining this project.

aik099 commented 7 years ago

Would it make sense to create a way to check the session status via the API?

It is REST API and in REST there is no session. Each API call is using credentials you provided. So you can just make any API call and see if it ends up in unauthorized exception.