Получить значения из HttpRequestException в другом приложении - PullRequest
0 голосов
/ 23 мая 2018

Я отправляю Exception из одного веб-приложения и получаю его в другом.Как я могу получить значения из HttpRequestException в этом случае?

отправить из:

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

получить в другом:

catch (HttpRequestException e)
{
    this.logger.LogError(
      string.Format("Ошибка запроса {0}", requestUri.AbsoluteUri),
      LogCategoryRepository.ApiCashdesk,
      e);
    throw;
}

1 Ответ

0 голосов
/ 26 мая 2018

Хорошо.Вы просто создаете класс:

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

И используете его:

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;
                }
            }
...