Skip to content

Commit 1ddec59

Browse files
committed
Change to expand docs with error handling.
1 parent dceb5e1 commit 1ddec59

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ gem "github_api"
7777
* [4. Pagination](#4-pagination)
7878
* [4.1 Auto pagination](#41-auto-pagination)
7979
* [5. Error Handling](#5-error-handling)
80+
* [5.1 Client Error](#51-client-error)
81+
* [5.2 Service Error](#52-service-error)
82+
* [5.2.1 Data](#521-data)
83+
* [5.2.2 Error Messages](#522-error-messages)
8084
* [6. Examples](#6-examples)
8185
* [6.1 Rails](#61-rails)
8286
* [6.2 Manipulating Files](#62-manipulating-files)
@@ -582,14 +586,15 @@ Github::Client::Repos.new.list user: '...', auto_pagination: true
582586

583587
## 5 Error Handling
584588

585-
The generic error class `Github::Error::GithubError` will handle both the client (`Github::Error::ClientError`) and service (`Github::Error::ServiceError`) side errors. For instance in your code you can catch errors like
589+
The generic error class `Github::Error::GithubError` will handle both the client (`Github::Error::ClientError`) and service (`Github::Error::ServiceError`) side errors.
590+
591+
For instance in your code you can catch errors like
586592

587593
```ruby
588594
begin
589595
# Do something with github_api gem
590596
rescue Github::Error::GithubError => e
591597
puts e.message
592-
593598
if e.is_a? Github::Error::ServiceError
594599
# handle GitHub service errors such as 404
595600
elsif e.is_a? Github::Error::ClientError
@@ -598,6 +603,24 @@ rescue Github::Error::GithubError => e
598603
end
599604
```
600605

606+
### 5.1 Client Error
607+
608+
Any time **Github** client has a problem sending request a `Github::Error::ClientError` is raised that will provide a summary of the problem and possible solutions.
609+
610+
### 5.2 Service Error
611+
612+
When the **Github** client receives a HTTP response from GitHub service that indicates error then `Github::Error::ServiceError` is raised.
613+
614+
There are number of specific error types such as `Github::Error::NotAcceptable` when `406` status code is returned.
615+
616+
#### 5.2.1 Data
617+
618+
When `Github::Error::ServiceError` is raised you can call `data` to access it payload in JSON format.
619+
620+
#### 5.2.2 Error messages
621+
622+
Anytime there are error messages provided with `Github::Error::ServiceError` you can access them by calling `error_messages` helper.
623+
601624
## 6 Examples
602625

603626
### 6.1 Rails

0 commit comments

Comments
 (0)