Katana / OWIN Debugging & app.UseErrorPage

I have time to do R&D and play with OWIN today.

I want the OWIN WebAPI service to work for all data interactions, and a separate SPA project for the web interface using angular.

All code is shamelessly stolen from various random blog posts, and it just fits this "new technology."

Enter

  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 go to   [http: // localhost: 85 / fail] I get a very sexy error page.

But when I clicked [http: // l0calhost: 85 / api / accounts / 5] , the error displays as json / xml.

  • Any way to force API Controller exceptions to use the AppBuilder error engine?
  • Will it frown? (He feels dirty ...)
+4
1

( 5.0) -API , , . , HTTP- json/xml. , .

IMO, -API, . Javascript, , html?. , .

+5

All Articles