go-chi / go-chi/hostrouter

Allow custom NotFound handler

Open
#7 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
80
Forks
15
PR merge metrics
No merged PRs in 30d

Description

I would like to use a custom handler for unmatched requests, so we can track metrics and return a custom error message. This is currently not supported, since hostrouter always invokes `http.Error`:

https://github.com/go-chi/hostrouter/blob/03da900f6d45aaf0d5a1f392e2bafe8437ae5102/hostrouter.go#L44

It would be very nice if we could set a custom handler for that case, similar to [chi's NotFound hook](https://go-chi.io/#/pages/routing?id=making-custom-404-and-405-handlers)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at hostrouter.go line 44, where unmatched requests currently invoke http.Error, and compare the requested behavior with chi's NotFound hook. Define how a custom handler should be configured for unmatched requests, then verify that it can track metrics and return a custom error message.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.