-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
63 lines (51 loc) · 1.18 KB
/
error.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package ela
import (
// "errors"
"fmt"
"github.com/gogather/com"
"github.com/gogather/com/log"
// "reflect"
"strings"
)
func servError(ctx *Context, err string, status int, useDefault bool) {
inj := newInjection()
controller := getController(fmt.Sprintf("@%d", status))
if controller == nil {
ctx.SetHeader("Content-Type", "text/html")
ctx.SetStatus(status)
ctx.Write(err)
return
}
routerElement := controller.(uriMode)
f := routerElement.fun
if f != nil && !useDefault {
functions := f
defer func() {
if r := recover(); r != nil {
ctx.SetHeader("Content-Type", "text/html")
ctx.SetStatus(status)
ctx.Write(err)
}
}()
ctx.SetStatus(status)
// just get and execute first controller
if len(functions) >= 1 {
function := functions[0]
inj.headMiddleware(ctx)
inj.appendMiddleware(err)
_, err := inj.injectFuc(function)
if err != nil {
log.Redf("injection failed: %s\n", err)
}
}
} else {
ctx.SetHeader("Content-Type", "text/html")
ctx.SetStatus(status)
ctx.Write(err)
}
}
func fmtErrorHtml(content string) string {
content = com.HTMLEncode(content)
content = strings.Replace(content, "\n", "<br>", -1)
return content
}