3

I send Exception from one web application and get it in another. How do I can get values from HttpRequestException in this case?

send from:

context.Response = new HttpResponseMessage(apiError.StatusCode)
{
    Content = new ObjectContent<ApiError>(apiError,
       new JsonMediaTypeFormatter(), @"application/json")
};
return context;

get in another:

catch (HttpRequestException e)
{
    this.logger.LogError(
      string.Format("Ошибка запроса {0}", requestUri.AbsoluteUri),
      LogCategoryRepository.ApiCashdesk,
      e);
    throw;
}
Aleks Andreev
  • 7,016
  • 8
  • 29
  • 37
Kseniya Yudina
  • 137
  • 1
  • 11

1 Answers1

0

Ok. You just create a class:

 public class ErrorDetails
 {
    public string Details { get; set; }
 }

And use it:

try
            {
                using (var response = await client.SendAsync(request).ConfigureAwait(false))
                {
                    if(!response.IsSuccessStatusCode)
                    {
                        ***var error = await response.Content.ReadAsAsync<ErrorDetails>().ConfigureAwait(false);***
                        throw new HttpRequestException(error.Details);
                    }
                    response.EnsureSuccessStatusCode();
                    var result = await response.Content.ReadAsAsync<TResponse>().ConfigureAwait(false);
                    return result;
                }
            }
Kseniya Yudina
  • 137
  • 1
  • 11