How to handle not registered route in Grapevine? #149
-
Hello, Scott! I want to implement this feature using Grapevine. When Grapevine raises an error because of unregistered route, I want it to be intercepted and return a standard JSON reply with a 200 status code, like this: Could you please help me with this? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If no route is found to handle the request (or if no route sends a response and one is required), then the status of the response is set to 501 Not Implemented. You can intercept this by providing either a global or local error handler. Note Global error handlers are available on all (server.Router as Router).LocalErrorHandlers.Add(HttpStatusCode.NotImplemented, async (ctx, ex) =>
{
await ctx.Response.SendResponseAsync("Your response goes here");
}); |
Beta Was this translation helpful? Give feedback.
If no route is found to handle the request (or if no route sends a response and one is required), then the status of the response is set to 501 Not Implemented. You can intercept this by providing either a global or local error handler.
Note
Global error handlers are available on all
Router
instances, whereas local error handlers are specific to an instance. Unless your use case specifically calls for multiple servers, creating a local error handler is what you want to do.