Skip to content

Commit

Permalink
Fix possible nil error during logging
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Apr 14, 2023
1 parent 74c55c8 commit cf7cec7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/soroban-rpc/internal/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ func (r *rpcLogger) LogRequest(ctx context.Context, req *jrpc2.Request) {
func (r *rpcLogger) LogResponse(ctx context.Context, rsp *jrpc2.Response) {
// TODO: Print the elapsed time (there doesn't seem to be a way to it with with jrpc2, since
// LogRequest cannot modify the context)
r.logger.WithFields(log.F{
logger := r.logger.WithFields(log.F{
"subsys": "jsonrpc",
"req": middleware.GetReqID(ctx),
"json_req": rsp.ID(),
"error": rsp.Error().Error(),
// TODO: is this overkill?
"result": rsp.ResultString(),
}).Info("finished JSONRPC request")
})
if err := rsp.Error(); err != nil {
logger = logger.WithField("error", err.Error())
}
logger.Info("finished JSONRPC request")
}

0 comments on commit cf7cec7

Please sign in to comment.