Skip to content

Commit 8f2b47d

Browse files
committed
Switch to register 404, return error and warn at toplevel
1 parent 4585c13 commit 8f2b47d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

nextrouter/nextrouter.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ func Handler(fileSystem fs.FS, options *Options) http.Handler {
5252
router.NotFound(fileHandler.ServeHTTP)
5353

5454
// Finally, if there is a 404.html available, serve that
55-
serve404IfAvailable(fileSystem, router, *options)
55+
err := register404(fileSystem, router, *options)
56+
if (err != nil) {
57+
// An error may be expected if a 404.html is not present
58+
options.Logger.Warn(context.Background(), "Unable to find 404.html", slog.Error(err))
59+
}
5660

5761
return router
5862
}
@@ -180,12 +184,12 @@ func serveFile(router chi.Router, fileSystem fs.FS, fileName string, options Opt
180184
router.Get("/"+fileNameWithoutExtension+"/", handler)
181185
}
182186

183-
func serve404IfAvailable(fileSystem fs.FS, router chi.Router, options Options) {
187+
func register404(fileSystem fs.FS, router chi.Router, options Options) error {
184188
// Get the file contents
185189
fileBytes, err := fs.ReadFile(fileSystem, "404.html")
186190
if err != nil {
187191
// An error is expected if the file doesn't exist
188-
return
192+
return err
189193
}
190194

191195
router.NotFound(func(writer http.ResponseWriter, request *http.Request) {
@@ -196,6 +200,8 @@ func serve404IfAvailable(fileSystem fs.FS, router chi.Router, options Options) {
196200
return
197201
}
198202
})
203+
204+
return nil
199205
}
200206

201207
// isDynamicRoute returns true if the file is a NextJS dynamic route, like `[orgs]`

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy