pages-server/html/error_std.go

24 lines
542 B
Go
Raw Normal View History

2022-07-15 16:10:41 +00:00
//go:build !fasthttp
package html
import (
"io"
2022-08-28 14:21:37 +00:00
"strings"
2022-07-27 15:25:08 +00:00
"codeberg.org/codeberg/pages/server/context"
2022-07-15 16:10:41 +00:00
)
// ReturnErrorPage sets the response status code and writes NotFoundPage to the response body, with "%status" replaced
// with the provided status code.
2022-08-28 14:21:37 +00:00
func ReturnErrorPage(ctx *context.Context, msg string, code int) {
2022-07-27 15:25:08 +00:00
ctx.RespWriter.Header().Set("Content-Type", "text/html; charset=utf-8")
ctx.RespWriter.WriteHeader(code)
2022-07-15 16:10:41 +00:00
2022-08-28 14:21:37 +00:00
if msg == "" {
msg = errorBody(code)
}
2022-08-28 14:53:30 +00:00
_, _ = io.Copy(ctx.RespWriter, strings.NewReader(msg))
2022-07-15 16:10:41 +00:00
}