pages-server/html/error.go

28 lines
589 B
Go
Raw Normal View History

2021-12-05 13:47:33 +00:00
package html
import (
"bytes"
2022-07-15 16:10:41 +00:00
"net/http"
2021-12-05 13:47:33 +00:00
"strconv"
)
2022-07-15 16:10:41 +00:00
func errorMessage(statusCode int) string {
message := http.StatusText(statusCode)
switch statusCode {
case http.StatusMisdirectedRequest:
2021-12-05 13:47:33 +00:00
message += " - domain not specified in <code>.domains</code> file"
2022-07-15 16:10:41 +00:00
case http.StatusFailedDependency:
2021-12-05 13:47:33 +00:00
message += " - target repo/branch doesn't exist or is private"
}
2022-07-15 16:10:41 +00:00
return message
}
// TODO: use template engine?
func errorBody(statusCode int) []byte {
return bytes.ReplaceAll(NotFoundPage,
[]byte("%status"),
[]byte(strconv.Itoa(statusCode)+" "+errorMessage(statusCode)))
2021-12-05 13:47:33 +00:00
}