Skip to content

Commit 39fd7c5

Browse files
authored
Document error handling (#472)
1 parent a48fba7 commit 39fd7c5

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

docs/docs/docs.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,37 @@ val user1 = Github[IO](httpClient, accessToken).users.get("rafaparadela")
5959

6060
`user1` in this case is a `IO[GHResponse[User]]`.
6161

62+
## Error handling
63+
64+
Depending on the response issued by GitHub, you might find yourself in the unhappy path of
65+
`GHResponse`. In this case you will have a `Left` as `GHResponse#result` which contains a `GHError`.
66+
67+
The `GHError` ADT defines different cases based on the response's status code:
68+
- 400 maps to `BadRequestError`
69+
- 401 -> `UnauthorizedError`
70+
- 403 -> `ForbiddenError`
71+
- 404 -> `NotFoundError`
72+
- 422 -> `UnprocessableEntityError`
73+
- 423 -> `RateLimitExceededError`
74+
75+
Thanks to these, you can fine-grain your logic according to your needs. E.g. if you're hitting a
76+
`RateLimitExceededError`, it might be worth it to inspect the headers and wait accordingly before
77+
retrying your request.
78+
79+
We support an extensive set of errors. However, since GitHub's documentation regarding
80+
errors is sparse, it's definitely possible, or rather extremly likely, that this set of supported
81+
errors is not exhaustive.
82+
83+
If you find an unsupported error, which translates into either:
84+
- `UnhandledResponseError` which corresponds to a status code which was not handled, or
85+
- `JsonParsingError` which indicates that the JSON sent back by GitHub couldn't be decoded into
86+
the case classes defined by github4s,
87+
please create an issue at https://github.com/47degrees/github4s/issues.
88+
89+
## Using different effect types
90+
91+
Github4s supports different effect types which we will go through next.
92+
6293
### Using `F[_]: cats.effect.Sync`
6394

6495
Any type with a `cats.effect.Sync` instance can be used with this example, such as

0 commit comments

Comments
 (0)