Errors
A call the server answers with an error status throws OpenBiApiException. The server reports errors as RFC 9457 problem details, which the exception unpacks:
| Property | What it holds |
|---|---|
StatusCode |
The HTTP status code, for example 404 or 403. 0 where the call succeeded but the expected response body was empty. |
Message |
The server's own message, where it sent one. |
ValidationErrors |
For a 400 validation failure, the messages per field. |
ErrorCode |
For the OAuth endpoints, the standard error value, for example invalid_grant. |
RawResponseBody |
The response body as it came, for diagnostics. |
try
{
await client.CreateUserAsync(user, cancellationToken);
}
catch (OpenBiApiException ex) when (ex.StatusCode == 400 && ex.ValidationErrors is not null)
{
foreach (var (field, messages) in ex.ValidationErrors)
{
Console.WriteLine($"{field}: {string.Join(", ", messages)}");
}
}
The status codes follow HTTP:
401- no token, or an expired one. Log in again or refresh the token.403- the token is valid but lacks the permission the route needs.404- the resource does not exist.409- a conflict, for example an id that already exists or an object locked by another user.
A failure to reach the server at all - DNS, TLS, a refused connection, a timeout - is not an
OpenBiApiException but the HttpRequestException or TaskCanceledException of HttpClient itself.