private async Task <HttpResponseMessage> ConfigureAndSendRequest(ActionstepHttpRequestMessage actionstepHttpRequestMessage, CancellationToken cancellationToken) { if (actionstepHttpRequestMessage is null) { throw new ArgumentNullException(nameof(actionstepHttpRequestMessage)); } var actionstepRequest = actionstepHttpRequestMessage.ActionstepRequest; if (actionstepRequest is null) { throw new InvalidActionstepRequestException("The ActionstepRequest for this request was null. This shouldn't happen", actionstepHttpRequestMessage); } if (actionstepHttpRequestMessage.TokenSet is null) { throw new InvalidActionstepRequestException("The TokenSet for this request was null. This shouldn't happen", actionstepHttpRequestMessage); } if (actionstepHttpRequestMessage.TokenSet.ApiEndpoint is null) { throw new InvalidActionstepRequestException("The Actionstep API endpoint could not be determined for this request.", actionstepHttpRequestMessage); } // We have to set the URI in case the ApiEndpoint was updated in the TokenSet. var apiEndpoint = actionstepHttpRequestMessage.TokenSet.ApiEndpoint; actionstepHttpRequestMessage.RequestUri = new Uri(apiEndpoint, Path.Combine(apiEndpoint.AbsolutePath, actionstepRequest.RelativeResourcePath.TrimStart('/'))); // Set Authorisation as per TokenSet actionstepHttpRequestMessage.Headers.Authorization = actionstepHttpRequestMessage.TokenSet.AuthorizationHeaderValue; return(await base.SendAsync(actionstepHttpRequestMessage, cancellationToken)); }
private static string EnrichMessage(string message, ActionstepHttpRequestMessage actionstepHttpRequestMessage) => $"{message}" + $" (" + $"TokenSet Id: '{actionstepHttpRequestMessage?.TokenSet?.Id}'" + $"TokenSet UserId: '{actionstepHttpRequestMessage?.TokenSet?.UserId}'" + $"TokenSet OrgKey: '{actionstepHttpRequestMessage?.TokenSet?.OrgKey}'" + $", " + $"Original Uri: {actionstepHttpRequestMessage?.RequestUri}" + $")";
public InvalidActionstepRequestException(string message, ActionstepHttpRequestMessage actionstepHttpRequestMessage) : this(EnrichMessage(message, actionstepHttpRequestMessage)) { ActionstepRequest = actionstepHttpRequestMessage; }