-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathw3_engine_errors.go
More file actions
37 lines (30 loc) · 879 Bytes
/
Copy pathw3_engine_errors.go
File metadata and controls
37 lines (30 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package w3
import (
"net/http"
"codeberg.org/bbfh/w3/w3errs"
"codeberg.org/bbfh/w3/w3logs"
)
// Function responsible for rendering the error to clients
type ErrorHandler func(ctx *Context, err w3errs.Error)
func (engine *Engine) wrapErrorHandler(err_getter func(*Context) w3errs.Error) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
object_index, ctx := engine.pool.AcquireObject()
defer engine.pool.Release(object_index)
ctx.reset()
ctx.Writer.wrapped = writer
ctx.Writer.responseCode = 0
ctx.Request = request
engine.ErrorHandler(ctx, err_getter(ctx))
})
}
func defaultErrorHandler(ctx *Context, err w3errs.Error) {
if err.StatusCode >= 500 {
w3logs.LogError(
"%s %q → %s",
ctx.Request.Method,
ctx.Request.URL,
err.InternalText,
)
}
ctx.SendText(err.StatusCode, err.PublicText)
}