55package rest
66
77import (
8+ "fmt"
89 "log"
910 "net/http"
1011 "net/url"
@@ -32,7 +33,6 @@ type Context struct {
3233 code string
3334 err error
3435 status int
35- found bool
3636 end bool
3737 requestSent bool
3838 preTasksCalled bool
@@ -62,7 +62,6 @@ func (ctx *Context) destroy() {
6262 ctx .code = ""
6363 ctx .err = nil
6464 ctx .status = 0
65- ctx .found = false
6665 ctx .end = false
6766 ctx .requestSent = false
6867 ctx .preTasksCalled = false
@@ -154,6 +153,10 @@ func (ctx *Context) PostSend(task Task) {
154153}
155154
156155//////////////////////////////////////////////////
156+ func (ctx * Context ) shouldBreak () (flag bool ) {
157+ return ctx .end || ctx .code != ""
158+ }
159+
157160// Send data, which uses bytes or error if any
158161// Also, it calls pre-send and post-send registered hooks
159162func (ctx * Context ) send (data []byte , err error ) {
@@ -191,7 +194,7 @@ func (ctx *Context) send(data []byte, err error) {
191194
192195 if err != nil {
193196 //TODO: debugger mode
194- log .Println ( "Response Error: " , err )
197+ log .Printf ( "response error: %v " , err )
195198 }
196199 }
197200
@@ -220,9 +223,9 @@ func (ctx *Context) unhandledException() {
220223 }
221224
222225 if ctx .code != "" || ctx .err != nil {
223- msg := "Error Code: " + ctx .code
226+ msg := fmt . Sprintf ( "error code: %v" , ctx .code )
224227 if ctx .err != nil {
225- msg += " \n Error Message: " + ctx .err . Error ( )
228+ msg += fmt . Sprintf ( " \n error message: %v" , ctx .err )
226229 }
227230 ctx .SetHeader ("Content-Type" , "text/plain;charset=UTF-8" )
228231 if ctx .status < 400 {
@@ -237,9 +240,9 @@ func (ctx *Context) recover() {
237240 err := recover ()
238241 if err != nil {
239242 //TODO: debugger mode
240- log .Println ( "Runtime Error: " , err )
243+ log .Printf ( "runtime error: %v " , err )
241244 if ! ctx .requestSent {
242- http .Error (ctx .Response , "Internal Server Error" , http .StatusInternalServerError )
245+ http .Error (ctx .Response , http . StatusText ( http . StatusInternalServerError ) , http .StatusInternalServerError )
243246 }
244247 }
245248}
0 commit comments