Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PartnerException"/> class.
 /// </summary>
 /// <param name="info">The <see cref="SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param>
 /// <param name="context">The <see cref="StreamingContext" /> that contains contextual information about the source or destination.</param>
 protected PartnerException(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     errorCategory = (PartnerErrorCategory)info.GetInt32(nameof(ErrorCategory));
     requestContex = info.GetValue(PartnerContextFieldName, typeof(IRequestContext)) as IRequestContext;
     serviceError  = info.GetValue(ServiceErrorPayloadFieldName, typeof(ApiFault)) as ApiFault;
 }
Exemplo n.º 2
0
        private async Task <TResource> HandleResponseAsync <TResource>(HttpResponseMessage response, JsonConverter converter = null)
        {
            string content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                if (string.IsNullOrEmpty(content))
                {
                    content = string.Empty;
                }

                return(JsonConvert.DeserializeObject <TResource>(content, GetSerializationSettings(converter)));
            }

            PartnerErrorCategory errorCategory = GetErrorCategory(response.StatusCode);

            if (string.IsNullOrEmpty(content))
            {
                throw new PartnerException(
                          response.ReasonPhrase,
                          rootPartnerOperations.RequestContext,
                          errorCategory);
            }

            ApiFault fault = JsonConvert.DeserializeObject <ApiFault>(content, GetSerializationSettings(converter));

            throw new PartnerException(
                      fault,
                      rootPartnerOperations.RequestContext,
                      errorCategory);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PartnerException" /> class.
 /// </summary>
 /// <param name="message">The message that describes the error.</param>
 /// <param name="context">The context for the request.</param>
 /// <param name="errorCategory">The category for the error.</param>
 /// <param name="innerException">
 /// The exception that is the cause of the current exception, or a null reference
 /// (Nothing in Visual Basic) if no inner exception is specified.
 /// </param>
 public PartnerException(
     string message,
     IRequestContext context,
     PartnerErrorCategory errorCategory = PartnerErrorCategory.NotSpecified,
     Exception innerException           = null) : base(message, innerException)
 {
     this.errorCategory = errorCategory;
     requestContex      = context;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PartnerException" /> class.
 /// </summary>
 /// <param name="apiFault">The API fault object returned by the partner service.</param>
 /// <param name="context">The context for the request.</param>
 /// <param name="errorCategory">The category for the error.</param>
 /// <param name="innerException">
 /// The exception that is the cause of the current exception, or a null reference
 /// (Nothing in Visual Basic) if no inner exception is specified.
 /// </param>
 public PartnerException(
     ApiFault apiFault,
     IRequestContext context,
     PartnerErrorCategory errorCategory = PartnerErrorCategory.NotSpecified,
     Exception innerException           = null)
     : this(apiFault != null ? apiFault.ErrorMessage : string.Empty, context, errorCategory, innerException)
 {
     serviceError = apiFault;
 }
Exemplo n.º 5
0
        private async Task HandleResponseAsync(HttpResponseMessage response)
        {
            string content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                return;
            }

            ApiFault             fault         = JsonConvert.DeserializeObject <ApiFault>(content, GetSerializationSettings());
            PartnerErrorCategory errorCategory = GetErrorCategory(response.StatusCode);

            throw new PartnerException(
                      fault,
                      rootPartnerOperations.RequestContext,
                      errorCategory);
        }
Exemplo n.º 6
0
        private async Task HandleResponseAsync(HttpRequestMessage request, CancellationToken cancellationToken = default)
        {
            HttpResponseMessage response = await HttpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);

            string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                return;
            }

            ApiFault             fault         = JsonConvert.DeserializeObject <ApiFault>(responseContent, GetSerializationSettings());
            PartnerErrorCategory errorCategory = GetErrorCategory(response.StatusCode);

            throw new PartnerException(fault, requestContext, errorCategory)
                  {
                      Request  = new HttpRequestMessageWrapper(request, null),
                      Response = new HttpResponseMessageWrapper(response, responseContent)
                  };
        }
Exemplo n.º 7
0
        private async Task <TResource> HandleResponseAsync <TResource>(HttpRequestMessage request, JsonConverter converter = null, CancellationToken cancellationToken = default)
        {
            HttpResponseMessage response = await HttpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);

            string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                if (typeof(TResource) == typeof(HttpResponseMessage))
                {
                    return((TResource)Convert.ChangeType(response, typeof(TResource)));
                }

                if (string.IsNullOrEmpty(responseContent))
                {
                    responseContent = string.Empty;
                }

                return(JsonConvert.DeserializeObject <TResource>(responseContent, GetSerializationSettings(converter)));
            }

            PartnerErrorCategory errorCategory = GetErrorCategory(response.StatusCode);

            if (string.IsNullOrEmpty(responseContent))
            {
                throw new PartnerException(response.ReasonPhrase, requestContext, errorCategory)
                      {
                          Request  = new HttpRequestMessageWrapper(request, null),
                          Response = new HttpResponseMessageWrapper(response, responseContent)
                      };
            }

            ApiFault fault = JsonConvert.DeserializeObject <ApiFault>(responseContent, GetSerializationSettings(converter));

            throw new PartnerException(fault, requestContext, errorCategory)
                  {
                      Request  = new HttpRequestMessageWrapper(request, null),
                      Response = new HttpResponseMessageWrapper(response, responseContent)
                  };
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PartnerException" /> class.
 /// </summary>
 /// <param name="message">The message that describes the error.</param>
 /// <param name="innerException">
 /// The exception that is the cause of the current exception, or a null reference
 /// (Nothing in Visual Basic) if no inner exception is specified.
 /// </param>
 public PartnerException(string message, Exception innerException) : base(message, innerException)
 {
     errorCategory = PartnerErrorCategory.NotSpecified;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PartnerException" /> class.
 /// </summary>
 public PartnerException()
 {
     errorCategory = PartnerErrorCategory.NotSpecified;
 }