utils/errors.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package utils import ( "net/http" "watchman/schema" ) func HandleError(w http.ResponseWriter, r *http.Request, statusCode int, message string, err error) { w.WriteHeader(statusCode) response := schema.ResponseType{ Status: "ERROR", Message: message + err.Error(), RequestID: r.Context().Value(schema.RequestIDKey{}).(string), } SendResponse(w, r, response) } func HandleMethodNotAllowed(w http.ResponseWriter, r *http.Request, method string) { if r.Method != method { HandleError(w, r, http.StatusMethodNotAllowed, "Method "+method+" not allowed", nil) } } |