Skip to content

Commit

Permalink
🧹 Capture underlying error on codes.DataLoss
Browse files Browse the repository at this point in the history
We are throwing away the underlying error. Capturing it to better
understand why this happens
  • Loading branch information
jaym committed Sep 16, 2024
1 parent 97927b1 commit c4d2852
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}

rctx, rcancel, body, err := preProcessRequest(ctx, req)
rctx, rcancel, body, err := preProcessRequest(ctx, span, req)
if err != nil {
HttpError(span, w, req, err)
return
Expand All @@ -118,11 +118,12 @@ func (s *server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// preProcessRequest is used to preprocess the incoming request.
// It returns the context, a cancel function and the body of the request. The cancel function can be used to cancel
// the context. It also adds the http headers to the context.
func preProcessRequest(ctx context.Context, req *http.Request) (context.Context, context.CancelFunc, []byte, error) {
func preProcessRequest(ctx context.Context, span trace.Span, req *http.Request) (context.Context, context.CancelFunc, []byte, error) {
// read body content
body, err := io.ReadAll(req.Body)
defer req.Body.Close()
if err != nil {
span.RecordError(err)
return nil, nil, nil, status.Error(codes.DataLoss, "unrecoverable data loss or corruption")
}

Expand Down

0 comments on commit c4d2852

Please sign in to comment.