Esempio n. 1
0
        public async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct = default)
        {
            await Credentials.ApplyAsync(request);

            var response = await Http.SendAsync(request, ct);

            if (!response.IsSuccessStatusCode)
            {
                JetfireApiError error = null;
                try
                {
                    var body = await response.Content.ReadAsStringAsync();

                    error = JsonSerializer.Deserialize <JetfireApiError>(body, JsonConfig.SerializerOptions);
                }
                catch (Exception) { }

                throw new JetfireApiException(
                          response.StatusCode,
                          request.Method,
                          request.RequestUri,
                          error
                          );
            }

            return(response);
        }
Esempio n. 2
0
 public JetfireApiException(
     HttpStatusCode statusCode,
     HttpMethod method,
     Uri uri,
     JetfireApiError error
     ) : base(MakeMessage(statusCode, method, uri, error))
 {
     StatusCode = statusCode;
     Method     = method;
     Uri        = uri;
     Error      = error;
 }
Esempio n. 3
0
        static string MakeMessage(
            HttpStatusCode status,
            HttpMethod method,
            Uri uri,
            JetfireApiError error
            )
        {
            var statusMessage = ((int)status).ToString();

            if (Enum.IsDefined(typeof(HttpStatusCode), status))
            {
                statusMessage += $" {status}";
            }
            var message = $"{method} {uri} failed with status {statusMessage}";

            if (error != null)
            {
                message += $": [{error.Type}] {error.Message}";
            }
            return(message);
        }