Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
func check(err error) {
if err != nil {
panic(err)
}
}
func (h *APIHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
defer func() {
if p := recover(); p != nil {
switch e := p.(type) {
case *silentError:
// nothing
case *clientError:
rw.Header().Set("Content-Type", "text/plain; charset=utf-8")
rw.WriteHeader(400)
fmt.Fprintln(rw, e.err.Error())
default:
rw.Header().Set("Content-Type", "text/plain; charset=utf-8")
rw.WriteHeader(500)
fmt.Fprintln(rw, "internal error")
}
}
}
...
}
func (h *APIHandler) Updates(rw http.ResponseWriter, req *http.Request) {
...
check(err)
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment