5
5
package rest
6
6
7
7
import (
8
+ "fmt"
8
9
"log"
9
10
"net/http"
10
11
"net/url"
@@ -32,7 +33,6 @@ type Context struct {
32
33
code string
33
34
err error
34
35
status int
35
- found bool
36
36
end bool
37
37
requestSent bool
38
38
preTasksCalled bool
@@ -62,7 +62,6 @@ func (ctx *Context) destroy() {
62
62
ctx .code = ""
63
63
ctx .err = nil
64
64
ctx .status = 0
65
- ctx .found = false
66
65
ctx .end = false
67
66
ctx .requestSent = false
68
67
ctx .preTasksCalled = false
@@ -154,6 +153,10 @@ func (ctx *Context) PostSend(task Task) {
154
153
}
155
154
156
155
//////////////////////////////////////////////////
156
+ func (ctx * Context ) shouldBreak () (flag bool ) {
157
+ return ctx .end || ctx .code != ""
158
+ }
159
+
157
160
// Send data, which uses bytes or error if any
158
161
// Also, it calls pre-send and post-send registered hooks
159
162
func (ctx * Context ) send (data []byte , err error ) {
@@ -191,7 +194,7 @@ func (ctx *Context) send(data []byte, err error) {
191
194
192
195
if err != nil {
193
196
//TODO: debugger mode
194
- log .Println ( "Response Error: " , err )
197
+ log .Printf ( "response error: %v " , err )
195
198
}
196
199
}
197
200
@@ -220,9 +223,9 @@ func (ctx *Context) unhandledException() {
220
223
}
221
224
222
225
if ctx .code != "" || ctx .err != nil {
223
- msg := "Error Code: " + ctx .code
226
+ msg := fmt . Sprintf ( "error code: %v" , ctx .code )
224
227
if ctx .err != nil {
225
- msg += " \n Error Message: " + ctx .err . Error ( )
228
+ msg += fmt . Sprintf ( " \n error message: %v" , ctx .err )
226
229
}
227
230
ctx .SetHeader ("Content-Type" , "text/plain;charset=UTF-8" )
228
231
if ctx .status < 400 {
@@ -237,9 +240,9 @@ func (ctx *Context) recover() {
237
240
err := recover ()
238
241
if err != nil {
239
242
//TODO: debugger mode
240
- log .Println ( "Runtime Error: " , err )
243
+ log .Printf ( "runtime error: %v " , err )
241
244
if ! ctx .requestSent {
242
- http .Error (ctx .Response , "Internal Server Error" , http .StatusInternalServerError )
245
+ http .Error (ctx .Response , http . StatusText ( http . StatusInternalServerError ) , http .StatusInternalServerError )
243
246
}
244
247
}
245
248
}
0 commit comments