Skip to content

Handle a Security API response

Centralizes response handling for every SecurityApi GET call: deserializes a successful response, or throws a SecurityClientException wrapping the error for any non-successful response.

Field Value
Operation ID OP-15
Trigger Any SecurityClient method (OP-04 through OP-08) completes its underlying remote GET call.
Inputs A urlPath and the underlying IHttpRequestResult/IHttpJsonClient response.
Outputs The deserialized T result, or a thrown SecurityClientException.
Primary components SecurityClient.HandleSecurityServiceGetResponse<T>
Entry point src/SAIF.NetCore.AuthService/SAIF.NetCore.AuthService/SAIF.NetCore.AuthService/Clients/SecurityClient.cs

Steps

  1. await HttpClient.GetAsync(urlPath) via the injected IHttpJsonClient.
  2. If result.IsSuccessful, return result.GetResult<T>(); otherwise throw new SecurityClientException(result.ErrorMessage, result.ErrorException) when ErrorException is not null, or new SecurityClientException(result.ErrorMessage) otherwise (BR-AUTH-011)

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([GET request completes]) --> Success{IsSuccessful?}
    Success -->|Yes| Return([Return deserialized result])
    Success -->|No| HasInner{ErrorException present?}
    HasInner -->|Yes| ThrowInner([Throw SecurityClientException with inner exception])
    HasInner -->|No| ThrowPlain([Throw SecurityClientException with message only])

Failure and edge-case behavior

  • There is no null/false/default fallback for a non-successful response; every caller must be prepared to catch SecurityClientException.

Sources

  • src/SAIF.NetCore.AuthService/SAIF.NetCore.AuthService/SAIF.NetCore.AuthService/Clients/SecurityClient.cs