Interesting, how many there are such 3rd party's products that AWS offers as a service?
Who will be the next for license changing, Redis?
type HTTPError interface {
GetHTTPCode() int
}
func ServeHTTP(w http.ResponseWriter, req \*http.Request) {
result, err := DoTheActualThing()
if err != nil {
statusCode := http.StatusInternalServerError
if httpError, ok := err.(HTTPError); ok {
statusCode = httpError.GetHTTPCode()
}
http.Error(w, ..., statusCode)
return
}
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(result)
}
You can apply the same approach for the HTTP body in case of error.