falcor-hapi icon indicating copy to clipboard operation
falcor-hapi copied to clipboard

How can we catch 'Function does not exist' errors?

Open ggoodman opened this issue 10 years ago • 2 comments

ggoodman avatar Mar 03 '16 22:03 ggoodman

Would you like to catch them on the client or on the server?

jhusain avatar Mar 07 '16 17:03 jhusain

@jhusain currently, when a call is made to the server for a path that either doesn't exist or has no call defined, an exception will be thrown by falcor-router.

That exception is caught by hapi internals and results in a json 500 response instead of a jsonGraph response with my own 404-style error and metadata.

It seems like the structure of this plugin makes it difficult to handle. I suppose a onPostHandler extension could transform this for the /model.json path, but this logic would be nicer to have in the plugin itself.

In the spirit of hapi's declarative nature, I think something like this would be nice:

  app.route({
    method: ['GET', 'POST'],
    path: '/model.json',
    handler: {
        falcor: {
            routes: routes,                                         // Your routes
            cacheRoutes: true,                                      // Whether to cache your routes, default to true
            options: {debug: true},                                 // Option to give to Falcor router
            initialize: function() {                                // Optional initialize method
               this.foo = this.req.payload.meaningoflife || 42;
            },
            routerClass: MyRouterClass,                             // Optional routerClass to use
            errorSelector: myErrorSelector                          // NEW: Optional method to handle uncaught exceptions
        }
    }
  });

ggoodman avatar Mar 07 '16 18:03 ggoodman