Add Request error Logging
This commit is contained in:
parent
4f660a3e9e
commit
0565f99212
1 changed files with 6 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue