title: Returning Error Message from Web API
body: <p>I have a Web API controller method...</p>
  
  <pre><code>    [HttpGet]
      [Route("~/Api/Tag/GetTagTaskMappings")]
      public IHttpActionResult GetTagTaskMappings()
      {
          try
          {
              var tagTaskMappings = _tagRepository.GetTagTaskMappings();
  
              if (tagTaskMappings == null)
              {
                  return NotFound();
              }
              return Ok(tagTaskMappings);
          }
          catch (Exception ex)
          {
              return InternalServerError(ex.InnerException);
          }
      }
  </code></pre>
  
  <p>I am using Postman to debug the method. 
  I am testing the Web API in 2 scenarios...</p>
  
  <ol>
  <li><p>Running in Visual Studio (IIS Express)</p></li>
  <li><p>Running on IIS Manager on a remote server</p></li>
  </ol>
  
  <p>Using Postman I get the desired results from scenario <strong>1</strong> test...</p>
  
  <pre><code>{
      "Message": "An error has occurred.",
      "ExceptionMessage": "No Tag/Task Relationship found",
      "ExceptionType": "System.Data.SqlClient.SqlException",
      "StackTrace": "   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady)\r\n   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n   at System.Data.SqlClient.SqlDataReader.get_MetaData()\r\n   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task&amp; task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task&amp; task, Boolean&amp; usedCache, Boolean asyncWrite, Boolean inRetry)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)\r\n   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.&lt;Reader&gt;b__c(DbCommand t, DbCommandInterceptionContext`1 c)\r\n   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)\r\n   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)\r\n   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)"
  }
  </code></pre>
  
  <p>However, for scenario <strong>2</strong> test, I only get this back from Postman...</p>
  
  <pre><code>{
      "Message": "An error has occurred."
  }
  </code></pre>
  
  <p>Any idea why I am not getting the ExceptionMessage? Am I error handling correctly?</p>
  
  <p>The only difference I see in Postman is scenario 1 has one extra header...</p>
  
  <pre><code>X-SourceFiles →=?UTF-8?B?XFxTVlB
  </code></pre>