1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00

Use errors.Is/errors.As instead of == comparisons against errors

This commit is contained in:
Michael Bahr 2026-06-11 13:47:36 +00:00
parent 4756698b1e
commit 95b3fbfc6d
No known key found for this signature in database
3 changed files with 8 additions and 4 deletions

View file

@ -2,6 +2,7 @@ package jsonrpc2
import (
"context"
"errors"
)
// HandlerWithError implements Handler by calling the func for each
@ -31,14 +32,15 @@ func (h *HandlerWithErrorConfigurer) Handle(ctx context.Context, conn *Conn, req
err = resp.SetResult(result)
}
if e, ok := err.(*Error); ok {
var e *Error
if errors.As(err, &e) {
resp.Error = e
} else if err != nil {
resp.Error = &Error{Message: err.Error()}
}
err = conn.SendResponse(ctx, resp)
if err != nil && (err != ErrClosed || !h.suppressErrClosed) {
if err != nil && (!errors.Is(err, ErrClosed) || !h.suppressErrClosed) {
conn.logger.Printf("jsonrpc2 handler: sending response %s: %v\n", resp.ID, err)
}
}