Skip to content

Commit

Permalink
feat(ErrorFilter): x-global-transaction-id and `X-DP-Watson-Tran-ID…
Browse files Browse the repository at this point in the history
…` are now included in the error message
  • Loading branch information
mediumTaj committed Oct 29, 2018
1 parent 596d1fe commit 5fe2aa1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/IBM.WatsonDeveloperCloud/Http/Filters/ErrorFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*
*/

using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using IBM.WatsonDeveloperCloud.Http.Exceptions;
using Newtonsoft.Json;

Expand All @@ -29,8 +31,24 @@ public void OnResponse(IResponse response, HttpResponseMessage responseMessage)
{
if (!responseMessage.IsSuccessStatusCode)
{
HttpHeaders responseHeaders = responseMessage.Headers;

IEnumerable<string> globalTransactionId;
string globalTransactionIdString = "";
if (responseHeaders.TryGetValues("x-global-transaction-id", out globalTransactionId))
{
globalTransactionIdString = string.Join(", ", globalTransactionId);
}

IEnumerable<string> watsonTransactionId;
string watsonTransactionIdString = "";
if (responseHeaders.TryGetValues("X-DP-Watson-Tran-ID", out watsonTransactionId))
{
watsonTransactionIdString = string.Join(", ", watsonTransactionId);
}

ServiceResponseException exception =
new ServiceResponseException(response, responseMessage, $"The API query failed with status code {responseMessage.StatusCode}: {responseMessage.ReasonPhrase}");
new ServiceResponseException(response, responseMessage, $"The API query failed with status code {responseMessage.StatusCode}: {responseMessage.ReasonPhrase} | x-global-transaction-id: {globalTransactionIdString} | X-DP-Watson-Tran-ID: {watsonTransactionIdString}");

var error = responseMessage.Content.ReadAsStringAsync().Result;

Expand Down

0 comments on commit 5fe2aa1

Please sign in to comment.