public void Configuration(IAppBuilder app) { app.UseErrorPage(); // Handles unhandled exceptions app.UseAppFuncExceptionHandler(); // Handles exceptions thrown by the application }
public void Configuration(IAppBuilder app) { app.UseErrorPage(); // Handles unhandled exceptions app.UseAppFuncExceptionHandler((error, context) => { context.Response.StatusCode = error.StatusCode; context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(new { error = error.Message })); }); }The AppFunc Error middleware is part of the Owin middleware library, which is available as a NuGet package. The package name is "Microsoft.Owin".