pages-server/html/error_std.go

20 lines
487 B
Go
Raw Normal View History

2022-07-15 16:10:41 +00:00
//go:build !fasthttp
package html
import (
"bytes"
"io"
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-07-27 15:25:08 +00:00
func ReturnErrorPage(ctx *context.Context, code int) {
ctx.RespWriter.Header().Set("Content-Type", "text/html; charset=utf-8")
ctx.RespWriter.WriteHeader(code)
2022-07-15 16:10:41 +00:00
2022-07-27 15:25:08 +00:00
io.Copy(ctx.RespWriter, bytes.NewReader(errorBody(code)))
2022-07-15 16:10:41 +00:00
}