Skip to content

Commit 39de8b4

Browse files
author
Kevin Hellemun
committed
Some markdown 📝.
1 parent 79593a2 commit 39de8b4

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

BunqSdk/Exception/EXCEPTIONS.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
## Exceptions
2+
3+
When you make a request via the SDK, there is a chance of request failing
4+
due to various reasons. When such a failure happens, an exception
5+
corresponding to the error occurred is raised.
6+
7+
8+
----
9+
#### Possible Exceptions
10+
11+
* `BadRequestException` If the request returns with status code `400`
12+
* `UnauthorizedException` If the request returns with status code `401`
13+
* `ForbiddenException` If the request returns with status code `403`
14+
* `NotFoundException` If the request returns with status code `404`
15+
* `MethodNotAllowedException` If the request returns with status code `405`
16+
* `TooManyRequestsException` If the request returns with status code `429`
17+
* `PleaseContactBunqException` If the request returns with status code `500`.
18+
If you get this exception, please contact us preferably via the support chat in the bunq app.
19+
* `UnknownApiErrorException` If none of the above mentioned exceptions are raised,
20+
this exception will be raised instead.
21+
22+
For more information regarding these errors, please take a look on the documentation
23+
page here: https://doc.bunq.com/api/1/page/errors
24+
25+
---
26+
#### Base exception
27+
All the exceptions have the same base exception which looks like this:
28+
```c#
29+
public class ApiException : System.Exception
30+
{
31+
private readonly string message;
32+
public int ResponseCode { get;}
33+
34+
public override string Message
35+
{
36+
get { return message; }
37+
}
38+
39+
/// <param name="responseCode">The HTTP Response code of the failed request.</param>
40+
/// <param name="message">The list of messages related to this exception.</param>
41+
public ApiException(int responseCode, string message) : base(message)
42+
{
43+
}
44+
}
45+
```
46+
This means that each exception will have the response code and the error message
47+
related to the specific exception that has been raised.
48+
49+
---
50+
#### Exception handling
51+
Because we raise different exceptions for each error, you can catch an error
52+
if you expect it to be raised.
53+
54+
```c#
55+
using Bunq.Sdk.Context;
56+
using Bunq.Sdk.Exception;
57+
58+
public class BadRequest
59+
{
60+
private const string API_KEY = "Some invalid API key"
61+
private const string DESCRIPTION = "This will throw BadRequestException."
62+
63+
public void Run()
64+
{
65+
try
66+
{
67+
ApiContext.Create(ApiEnvironmentType.SANDBOX, API_KEY, DEVICE_DESCRIPTION);
68+
}
69+
catch(BadRequestException error)
70+
{
71+
Console.WriteLine(error.getMessage())
72+
Console.WriteLine(error.getResponseCode())
73+
}
74+
}
75+
}
76+
```
77+
78+
This will ensure that you are ready for anything that might go wrong!

0 commit comments

Comments
 (0)