title: Returning JSON error message for Task<IHttpActionResult> method
body: <p>I have created an ASP.NET Web API that will call a java web service and display some results in JSON. When the java web service is not running, i get the error message as:</p>
  
  <blockquote>
    <p>{"Message":"An error has occurred.","ExceptionMessage":"The method or operation is not implemented.","ExceptionType":"System.NotImplementedException","StackTrace":"   at ApiClientJavaWebService.Models.RestfulClient.InternalServerError(Exception exception) in C:\Users\attsuap1\Desktop\Server Project\ApiClientJavaWebService\ApiClientJavaWebService\Models\RestfulClient.cs:line 43\r\n   at ApiClientJavaWebService.Models.RestfulClient.d__3.MoveNext() in C:\Users\attsuap1\Desktop\Server Project\ApiClientJavaWebService\ApiClientJavaWebService\Models\RestfulClient.cs:line 36\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()\r\n   at ApiClientJavaWebService.Controllers.AdditionController.d__1.MoveNext() in C:\Users\attsuap1\Desktop\Server Project\ApiClientJavaWebService\ApiClientJavaWebService\Controllers\AdditionController.cs:line 20\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Threading.Tasks.TaskHelpersExtensions.d__3`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}</p>
  </blockquote>
  
  <p>How do i change this to get the error message to be shown as <code>{"The server is not running."}</code>?</p>
  
  <p><strong>Here are my codes:</strong></p>
  
  <p><strong>AdditionClient.cs</strong></p>
  
  <pre><code>public class RestfulClient
  {
      private static HttpClient client;
      private static string BASE_URL = "http://localhost:8080/";
  
      static RestfulClient()
      {
          client = new HttpClient();
          client.BaseAddress = new Uri(BASE_URL);
          client.DefaultRequestHeaders.Accept.Add(
              new MediaTypeWithQualityHeaderValue("application/json"));
      }
  
      public async Task&lt;string&gt; addition(int firstNumber, int secondNumber)
      {
  
          try
          {
              var endpoint = string.Format("addition/{0}/{1}", firstNumber, secondNumber);
              var response = await client.GetAsync(endpoint);
              return await response.Content.ReadAsStringAsync();
          }
  
          catch (Exception e)
          {
  
          }
  
          return null;
      }
  }
  </code></pre>
  
  <p><strong>AdditionController.cs</strong></p>
  
  <pre><code>public class AdditionController : ApiController
  {
      private RestfulClient restfulClient = new RestfulClient();
      public async Task&lt;IHttpActionResult&gt; Get(int firstNumber, int secondNumber)
      {
          var result = await restfulClient.addition(firstNumber, secondNumber);
          var resultDTO = JsonConvert.DeserializeObject&lt;Temp&gt;(result);
          return Json(resultDTO);
      }
  }
  </code></pre>
  
  <p>Someone please do help me. Thank you so much in advance.</p>