Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Capture underlying error on codes.DataLoss #97

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading