-
Notifications
You must be signed in to change notification settings - Fork 1
Exception Handling
Mitchell Currey edited this page Jul 25, 2022
·
3 revisions
There are 4 supported exception types within the Integrations project library:
-
ForburyApiException
- Generic exception type for when the server hits an error processing your request. -
ForburyAuthenticationException
- When there is an issue obtaining an access token for requests, typically due to bad ClientId/ClientSecret. -
WebhookConfigurationException
- (Applicable only to Header webhook auth flow). Thrown when there is no matching endpoint configuration. -
WebhookSigningException
- (Applicable only to Header webhook auth flow). Thrown when the header auth key is not matching the Forbury server.
The main exception type is the ForburyApiException
. This will be thrown during processing Client
requests when something goes wrong.
This exception contains three core pieces of data:
-
Message
- a user-friendly description of the issue. -
HttpStatusCode
- the HttpCode returned from Forburys server (see response codes below for more). -
InnerException
- this is only populated when where is an issue with the data's return type. If you see this, please contact the Forbury Development Team with details ([email protected]).
There are 4 main response codes returned:
-
400
- Bad action. Typical response type. The message returned will be a user-friendly description of the issue. -
401
- Unauthorized. Your access token has expired, or you are trying to access an API that is not supported by the ClientCredentials workflow. -
403
- Forbidden action. The access token you are using does not have the required permissions to perform this action. -
500
- Unhandled exception. Could be due to bad data that is unexpected or an internal issue. If you see this, please contact the Forbury Development Team with details ([email protected]).
Below is an example of how to handle the different types of Forbury exceptions.
However, we would recommend building your own generic Forbury exception handler for this, or building it into your existing exception handler.
...
public async Task GetTeams(int amount = 20, int page = 1)
{
try
{
PagedResult<TeamDto> teams = await _forburyTeamApiClient.GetTeams(amount, page);
// Do work here
...
}
catch (ForburyApiException forburyException)
{
if (forburyException.HttpStatusCode == HttpStatusCode.BadRequest)
{
// Handle user friendly exception
var message = forburyException.Message;
...
}
else if (forburyException.HttpStatusCode == HttpStatusCode.Forbidden)
{
// Handle authorization exception (your API ClientId/Secret does not have access to this action)
...
}
else if (forburyException.InnerException != null)
{
// Handle mapping translation error (please contact Forbury if this happens)
...
}
else
{
// Something went wrong on Forbury servers (please contact Forbury if this happens)
...
}
}
catch (ForburyAuthenticationException forburyAuthenticationException)
{
// Handle authentication exception. Most likely related to invalid clientId/clientSecret, or incorrect setup.
...
}
}