public async Task <IHttpResponseModel> Execute(IHttpRequestModel httpRequest) { if (!(httpRequest is HttpRequestModel request)) { throw new ArgumentException("Client does not support request object type"); } IHttpResponseModel response = null; Exception caughtEx = null; try { ValidateRequest(request); response = await Send(request); return(response); } catch (Exception ex) { caughtEx = ex; throw; } finally { CommunicationLoggerEventManager.NotifyHttpRequestCompleted( this, new HttpCommunicationEventArgs(request, response, caughtEx)); } }
private string FormatResponseForLog(IHttpResponseModel response) { var sb = new StringBuilder(); sb.AppendLine("API Response:"); sb.AppendLine(); FormatAndPrintHeaders(sb, response.Headers); if (response.IsBodyInMemory) { string responseBody = response.GetBodyAsString(); if (!string.IsNullOrWhiteSpace(responseBody)) { sb.AppendLine(); sb.AppendLine(responseBody); } } return(sb.ToString()); }
public HttpCommunicationEventArgs(IHttpRequestModel request, IHttpResponseModel response, Exception caughtEx) { Request = request; Response = response; CaughtException = caughtEx; }