Skip to content

Commit bc57aa9

Browse files
committed
[example] Do not log errors when operation was cancelled
In case when HTTP connection was closed and the operation was still waiting to be run. Then OperationCancelled error is returned by processor.Run.
1 parent 8569438 commit bc57aa9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: _example/http/http.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"strconv"
1212

13+
"github.com/elgopher/batch"
1314
"github.com/elgopher/batch/_example/train"
1415
)
1516

@@ -50,12 +51,16 @@ func bookHandler(trainService TrainService) func(http.ResponseWriter, *http.Requ
5051
return
5152
}
5253

54+
if errors.Is(err, batch.OperationCancelled) {
55+
// context.Context was cancelled, so the operation
56+
// this could happen when connection was closed or request was cancelled (http/2)
57+
return
58+
}
59+
5360
if err != nil {
5461
writer.WriteHeader(http.StatusInternalServerError)
5562
fmt.Println("internal server error:", err)
5663
return
5764
}
58-
59-
writer.WriteHeader(http.StatusOK)
6065
}
6166
}

0 commit comments

Comments
 (0)