Exception handling
Gw2Sharp aims to be as friendly as possible when unexpected status codes are received from the Guild Wars 2 API. Whenever a request fails, a custom exception will be thrown for you to catch.
The following exceptions can be thrown from Gw2Sharp:
RequestException
: An exception occured during the requestRequestCanceledException
: The request has been canceledUnexpectedStatusException
: An unexpected HTTP status code was returned from the serverBadRequestException
(400): The client sent an invalid requestListTooLongException
(400): The list of requested resources is too longPageOutOfRangeException
(400): The requested page is out of range
AuthorizationRequiredException
(401, 403): The client is unauthorizedInvalidAccessTokenException
(401, 403): The access token is invalidMissingScopesException
(403): The access token does not have the required scopesMembershipRequiredException
(403): The user is not a member of the guildRestrictedToGuildLeadersException
(403): The user is not a leader of the guild
NotFoundException
(404): The requested resource has not been foundTooManyRequestsException
(429): Too many requests have been issued in a short period of timeServerErrorException
(500): The server encountered an errorServiceUnavailableException
(503): The server is temporarily unavailable
Tip
As you can see, all custom exceptions inherit from RequestException
.
This makes it easier to have a generic catch-all statement for Gw2Sharp.
However, certain exceptions may provide extra details as to why it has occured.
If you need that information, it's recommended to catch the specific exceptions first, before the more generic ones.