From 0565f992129dfb47688660e5b95818c7a5f4948c Mon Sep 17 00:00:00 2001 From: speatzle Date: Tue, 21 May 2024 15:40:45 +0200 Subject: [PATCH] Add Request error Logging --- rpc/request.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rpc/request.go b/rpc/request.go index bfa1aab..8496b94 100644 --- a/rpc/request.go +++ b/rpc/request.go @@ -14,6 +14,7 @@ func (s *server) handleRequest(ctx context.Context, c *websocket.Conn, data []by err := json.Unmarshal(data, &request) if err != nil { respondError(ctx, c, "", ERROR_JRPC2_PARSE_ERROR, fmt.Errorf("Error Parsing Request: %w", err), nil) + slog.ErrorContext(ctx, "Parsing Request", "err", err) return } @@ -21,6 +22,7 @@ func (s *server) handleRequest(ctx context.Context, c *websocket.Conn, data []by fun, ok := s.methods[request.Method] if !ok { respondError(ctx, c, request.ID, ERROR_JRPC2_METHOD_NOT_FOUND, fmt.Errorf("Method Not Found"), nil) + slog.ErrorContext(ctx, "Method Not Found") return } @@ -31,6 +33,7 @@ func (s *server) handleRequest(ctx context.Context, c *websocket.Conn, data []by result, err := fun(reqCtx, request) if err != nil { respondError(ctx, c, request.ID, 1000, fmt.Errorf("Method Error: %w", err), result) + slog.ErrorContext(ctx, "Method Error", "err", err) return } @@ -39,6 +42,7 @@ func (s *server) handleRequest(ctx context.Context, c *websocket.Conn, data []by rData, err = json.Marshal(result) if err != nil { respondError(ctx, c, request.ID, ERROR_JRPC2_INTERNAL, fmt.Errorf("Error Marshalling Response Data: %w", err), nil) + slog.ErrorContext(ctx, "Marshalling Response Data", "err", err) return } } @@ -50,12 +54,14 @@ func (s *server) handleRequest(ctx context.Context, c *websocket.Conn, data []by }) if err != nil { respondError(ctx, c, request.ID, ERROR_JRPC2_INTERNAL, fmt.Errorf("Error Marshalling Response: %w", err), nil) + slog.ErrorContext(ctx, "Marshalling Response", "err", err) return } err = c.Write(ctx, websocket.MessageText, resp) if err != nil { respondError(ctx, c, request.ID, ERROR_JRPC2_INTERNAL, fmt.Errorf("Error Sending Response: %w", err), nil) + slog.ErrorContext(ctx, "Sending Response", "err", err) return } }