In my web application, I have both web API and normal MVC in there I have created an extension for httpResponse
public static void ShowApplicationError(this HttpResponse response, string exceptionMessage,string innerException)
{
var result = JsonConvert.SerializeObject(new { error = exceptionMessage ,detail=innerException });
response.HttpContext.Response.WriteAsync(result);
}
and used in startup.cs for exception handling.
app.UseExceptionHandler(builder =>
{
builder.Run(async context =>
{
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
var error = context.Features.Get<IExceptionHandlerFeature>();
if (error != null)
{
context.Response.ShowApplicationError(error.Error.Message, error.Error.InnerException.Message);
}
});
});
like this. its works fine for both. i want to differentiate the error for each request. i dont want to show the json error for mvc end how do i do that.
areatoken to differentiate the requests and return the relevant type of response