1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-17 20:50:03 +02:00

transparently simplify control flow

This commit is contained in:
Kevin Gillette 2025-02-15 23:37:44 -07:00
parent 534fd43609
commit ec6ca95995
No known key found for this signature in database
GPG key ID: 93B201FCCF7BFC8B
4 changed files with 72 additions and 89 deletions

View file

@ -30,20 +30,16 @@ func (h *HandlerWithErrorConfigurer) Handle(ctx context.Context, conn *Conn, req
if err == nil {
err = resp.SetResult(result)
}
if err != nil {
if e, ok := err.(*Error); ok {
resp.Error = e
} else {
resp.Error = &Error{Message: err.Error()}
}
if e, ok := err.(*Error); ok {
resp.Error = e
} else if err != nil {
resp.Error = &Error{Message: err.Error()}
}
if !req.Notif {
if err := conn.SendResponse(ctx, resp); err != nil {
if err != ErrClosed || !h.suppressErrClosed {
conn.logger.Printf("jsonrpc2 handler: sending response %s: %v\n", resp.ID, err)
}
}
err = conn.SendResponse(ctx, resp)
if err != nil && (err != ErrClosed || !h.suppressErrClosed) {
conn.logger.Printf("jsonrpc2 handler: sending response %s: %v\n", resp.ID, err)
}
}