grim/goserve

e739eed19905
Parents be14d492fb16
Children 1a13ea69c95f
Print out an error message when we fail to open the custom 404 page
  • +10 -3
    response.go
  • --- a/response.go Sat Jan 04 04:38:21 2020 -0600
    +++ b/response.go Sat Jan 04 05:14:53 2020 -0600
    @@ -1,6 +1,7 @@
    package main
    import (
    + "fmt"
    "io/ioutil"
    "net/http"
    )
    @@ -29,9 +30,15 @@
    if w.code == http.StatusNotFound && w.notFoundFile != "" {
    notFoundData, err := ioutil.ReadFile(w.notFoundFile)
    - // if there's an error reading the file we ignore it so the default
    - // NotFound handler's data gets written
    - if err == nil {
    + if err != nil {
    + fmt.Printf(
    + "failed to load custom 404 file %q\n",
    + err,
    + )
    + } else {
    +
    + // if the file loaded overwrite the output that the original
    + // handler gave us.
    data = notFoundData
    }
    }