public async Task <HttpResponseMessage> SendAsync( string url, HttpMethod method, MimeType mimeType, HttpContent body = null) { CateHttpContext context = null; try { var uri = url.AppendTo(Configuration.BaseAddress); var request = new HttpRequestMessage(method, uri) { Content = body }; request.Accept(mimeType); context = new CateHttpContext(request, Configuration); return(await Client.SendAsync(request).ConfigureAwait(false)); } catch when(context != null && context.HasHandledException) { return(context.Response); } }
public CateHttpException(CateHttpContext context, string message, Exception inner) : base(message, inner) { Context = context; }
public CateSerializerException(CateHttpContext context, Type type, Exception inner) : this(context, $"Unable to deserialize the data into {type}.", inner) { }
private static string ToMessage(CateHttpContext context, Exception inner) { return(context.Response == null ? $"The request to {context.Uri.AbsoluteUri} ended without a response from the remote machine. {inner?.Message} {inner?.GetBaseException().Message}" : $"The request to {context.Uri.AbsoluteUri} ended with statuscode {(int)context.Response.StatusCode} {context.Response.ReasonPhrase}."); }
public CateHttpException(CateHttpContext context) : this(context, ToMessage(context, null), null) { }
public CateHttpException(CateHttpContext context, Exception inner) : this(context, ToMessage(context, inner), inner) { }