go-kit / go-kit/kit

Add Error Handling for Canceled Contexts during request lifecycle

Open
#1,277 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
27.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

### What would you like?

Various [lifecycle](https://github.com/go-kit/kit/blob/dfe43fa6a8d72c23e2205d0b80e762346e203f78/transport/http/server.go#L95) steps can cancel a `context.Context`, but it would be the responsibility of each consumer to verify the context isn't canceled. It would be great to add:

```go

for _, f := range s.before {
ctx = f(ctx, r)
if ctx.Err() == context.Canceled {
err := context.Cause(ctx)
s.errorHandler.Handle(ctx, err)
s.errorEncoder(ctx, err, w)
return
}
}

request, err := s.dec(ctx, r)
if err != nil {
s.errorHandler.Handle(ctx, err)
s.errorEncoder(ctx, err, w)
return
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.