Gracefully handles client request cancelations, instead of treating treating them as server errors (#1194)

* Gracefully handles client request cancelations, instead of logging them as a 500 error

* adds runner_addr to runner client logs
This commit is contained in:
Gerardo Viedma
2018-09-05 07:53:48 +01:00
committed by GitHub
parent b11c1e63a1
commit 0e01f3e547
2 changed files with 18 additions and 8 deletions

View File

@@ -28,6 +28,11 @@ func simpleError(err error) *models.Error {
// TODO delete me !
func handleV1ErrorResponse(ctx *gin.Context, err error) {
log := common.Logger(ctx)
if ctx.Request.Context().Err() == context.Canceled {
log.Info("request canceled")
return
}
w := ctx.Writer
var statuscode int
if e, ok := err.(models.APIError); ok {
@@ -63,9 +68,14 @@ func writeV1Error(ctx context.Context, w http.ResponseWriter, statuscode int, er
}
}
// handleV1ErrorResponse used to handle response errors in the same way.
// HandleErrorResponse used to handle response errors in the same way.
func HandleErrorResponse(ctx context.Context, w http.ResponseWriter, err error) {
log := common.Logger(ctx)
if ctx.Err() == context.Canceled {
log.Info("request canceled")
return
}
var statuscode int
if e, ok := err.(models.APIError); ok {
if e.Code() >= 500 {