Skip to content

How to handle not registered route in Grapevine? #149

Closed Answered by scottoffen
ThreeStars9908 asked this question in Q&A
Discussion options

You must be logged in to vote

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.

(server.Router as Router).LocalErrorHandlers.Add(HttpStatusCode.NotImplemented, async (ctx, ex) =>
{
    await ctx.Response.SendResponseAsync("Your response goes here");
});

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ThreeStars9908
Comment options

Answer selected by scottoffen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants