I've got some time to do R&D and have been playing around with OWIN as of today.
I'd like to have an OWIN WebAPI service running for all data interactions, and a separate Web front end SPA project making use of angular.
All code is shamelessly stolen from various random blog posts, and it just for coming to grips with this "new tech".
Startup
public class Startup
{
public void Configuration(IAppBuilder app)
{
#if DEBUG
app.UseErrorPage();
#endif
app.UseWelcomePage("/");
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
app.UseWebApi(config);
app.Run(context =>
{
if (context.Request.Path.ToString() == "/fail")
{
throw new Exception("Random exception");
}
context.Response.ContentType = "text/plain";
return context.Response.WriteAsync("App Init");
});
}
}
AccountsController
public class AccountsController : ApiController
{
// GET api/<controller>/5
public string Get(int id)
{
throw new Exception("Random exception");
}
}
If I navigate to [http://localhost:85/fail] I get a very sexy looking error page.
But when I hit [http://l0calhost:85/api/accounts/5], the error is exposed as json/xml.
- Any way to force the API Controller exceptions to use the AppBuilder error mechanism as well?
- Would this be frowned upon? (It feels kind of dirty...)