@@ -52,7 +52,11 @@ func Handler(fileSystem fs.FS, options *Options) http.Handler {
52
52
router .NotFound (fileHandler .ServeHTTP )
53
53
54
54
// 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
+ }
56
60
57
61
return router
58
62
}
@@ -180,12 +184,12 @@ func serveFile(router chi.Router, fileSystem fs.FS, fileName string, options Opt
180
184
router .Get ("/" + fileNameWithoutExtension + "/" , handler )
181
185
}
182
186
183
- func serve404IfAvailable (fileSystem fs.FS , router chi.Router , options Options ) {
187
+ func register404 (fileSystem fs.FS , router chi.Router , options Options ) error {
184
188
// Get the file contents
185
189
fileBytes , err := fs .ReadFile (fileSystem , "404.html" )
186
190
if err != nil {
187
191
// An error is expected if the file doesn't exist
188
- return
192
+ return err
189
193
}
190
194
191
195
router .NotFound (func (writer http.ResponseWriter , request * http.Request ) {
@@ -196,6 +200,8 @@ func serve404IfAvailable(fileSystem fs.FS, router chi.Router, options Options) {
196
200
return
197
201
}
198
202
})
203
+
204
+ return nil
199
205
}
200
206
201
207
// isDynamicRoute returns true if the file is a NextJS dynamic route, like `[orgs]`
0 commit comments