mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user