i have chain of claw http.handler
middlewares, first handler might write error response:
http.error(w, err.error(), http.statusunauthorized)
however other middlewares continue executing, don't want to. best way go this? tried checking status header after calling http.error()
, see if other 200:
status := w.header().get("status")
but status empty string.
you can use "naked" return
after error stop middleware chain execution.
from http documentation:
error replies request specified error message , http code. not otherwise end request; caller should ensure no further writes done w. error message should plain text.
from custom handlers , avoiding globals in go web applications :
func myhandler(w http.responsewriter, r *http.request) { session, err := store.get(r, "myapp") if err != nil { http.error(w, http.statustext(http.statusinternalservererror), http.statusinternalservererror) return // forget return, , handler continue on } .../... }
Comments
Post a Comment