Exemple #1
0
        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);
            }
        }
Exemple #2
0
 public CateHttpException(CateHttpContext context, string message,
                          Exception inner) : base(message, inner)
 {
     Context = context;
 }
Exemple #3
0
 public CateSerializerException(CateHttpContext context, Type type,
                                Exception inner) : this(context,
                                                        $"Unable to deserialize the data into {type}.", inner)
 {
 }
Exemple #4
0
 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}.");
 }
Exemple #5
0
 public CateHttpException(CateHttpContext context) : this(context,
                                                          ToMessage(context, null),
                                                          null)
 {
 }
Exemple #6
0
 public CateHttpException(CateHttpContext context, Exception inner) : this(context,
                                                                           ToMessage(context, inner),
                                                                           inner)
 {
 }