My Web Api when run locally (in Release mode) will return any errors in this format:
{
"Message": "An error has occurred.",
"ExceptionMessage": "No text specified",
"ExceptionType": "System.Exception",
"StackTrace": null
}
But after deployment/publish to an Azure VM, only this remains:
{
"Message": "An error has occurred."
}
API code:
try
{
var msg = ...
new MessageService().SaveMessage(msg)); // <-- does some checks; may throw.
return Ok();
}
catch (Exception ex)
{
return InternalServerError(ex);
}
I'd like it to be more detailed on Azure, like the local result.
Can this be achieved, and if so, how?
I already (temporarily) removed <compilation xdt:Transform="RemoveAttributes(debug)" />
from the <system.web>
part of Web.Release.config, and then re-deployed, but that made no difference.
Or am I using the wrong approach/pattern?
Obviously technical details should be limited, but right now we get no details at all.
I have a scenario with the same error, and the problem was a copy&paste in the route header attribute of a method. I have the same route for two methods
Check the new methods and Routes added.
If instead you use
then you can use the system.webServer error switch e.g.
Note the existingResponse attribute to preserve the error message.
For Web API 2, you can implement a custom IExceptionLogger that utilizes Azure Application Insights. Something like this:
Then you need to register it with Web API:
For this to work, you will need to have set up Application Insight in Azure and for your VS project, but that is a story for another time :) For more information, see Application Insights: Exception Telemetry
I had the same problem, the post is three years old, things have changed a little. If you setup a new Azure Mobile App with Visual Studio 2017 there is no longer a Global.asax.cs. I searched for hours, where to put this IncludeErrorDetailPolicy. It won't work without that setting.
You do it in your Startup.MobileApp.cs:
Don't forget, in your Web.config you also need to set:
Don't use that for production environment!
You could try adding the following to your Global.asax:
Note: I wouldn't recommend that you keep this setting on in a production environment.