Fixes to recent extension changes. (#568)

* Fixes to recent extension changes.

* Fixes issue where gin will continue calling the handler even if next() isn't called.

* Updated docs.
This commit is contained in:
Travis Reeder
2017-12-06 10:12:55 -08:00
committed by GitHub
parent 3096900d52
commit 6b8627d1c5
6 changed files with 52 additions and 22 deletions

View File

@@ -43,6 +43,12 @@ func HandleErrorResponse(ctx context.Context, w http.ResponseWriter, err error)
statuscode = http.StatusInternalServerError
err = ErrInternalServerError
}
WriteError(ctx, w, statuscode, err)
}
// WriteError easy way to do standard error response, but can set statuscode and error message easier than HandleErrorResponse
func WriteError(ctx context.Context, w http.ResponseWriter, statuscode int, err error) {
log := common.Logger(ctx)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(statuscode)
err = json.NewEncoder(w).Encode(simpleError(err))