mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: handle client connection close errors (#1196)
This commit is contained in:
@@ -18,6 +18,11 @@ var (
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
error: errors.New("Invalid JSON"),
|
error: errors.New("Invalid JSON"),
|
||||||
}
|
}
|
||||||
|
ErrClientCancel = err{
|
||||||
|
// The special custom error code to close connection without any response
|
||||||
|
code: 444,
|
||||||
|
error: errors.New("Client cancelled context"),
|
||||||
|
}
|
||||||
ErrCallTimeout = err{
|
ErrCallTimeout = err{
|
||||||
code: http.StatusGatewayTimeout,
|
code: http.StatusGatewayTimeout,
|
||||||
error: errors.New("Timed out"),
|
error: errors.New("Timed out"),
|
||||||
|
|||||||
@@ -28,12 +28,15 @@ func simpleError(err error) *models.Error {
|
|||||||
// TODO delete me !
|
// TODO delete me !
|
||||||
func handleV1ErrorResponse(ctx *gin.Context, err error) {
|
func handleV1ErrorResponse(ctx *gin.Context, err error) {
|
||||||
log := common.Logger(ctx)
|
log := common.Logger(ctx)
|
||||||
if ctx.Request.Context().Err() == context.Canceled {
|
|
||||||
log.Info("request canceled")
|
w := ctx.Writer
|
||||||
|
|
||||||
|
if ctx.Err() == context.Canceled {
|
||||||
|
log.Info("client context cancelled")
|
||||||
|
w.WriteHeader(models.ErrClientCancel.Code())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w := ctx.Writer
|
|
||||||
var statuscode int
|
var statuscode int
|
||||||
if e, ok := err.(models.APIError); ok {
|
if e, ok := err.(models.APIError); ok {
|
||||||
if e.Code() >= 500 {
|
if e.Code() >= 500 {
|
||||||
@@ -71,8 +74,10 @@ func writeV1Error(ctx context.Context, w http.ResponseWriter, statuscode int, er
|
|||||||
// HandleErrorResponse 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) {
|
func HandleErrorResponse(ctx context.Context, w http.ResponseWriter, err error) {
|
||||||
log := common.Logger(ctx)
|
log := common.Logger(ctx)
|
||||||
|
|
||||||
if ctx.Err() == context.Canceled {
|
if ctx.Err() == context.Canceled {
|
||||||
log.Info("request canceled")
|
log.Info("client context cancelled")
|
||||||
|
w.WriteHeader(models.ErrClientCancel.Code())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user