Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (c *Conn) close(cause error) error {
close(call.done)
}

if cause != nil && cause != io.EOF && cause != io.ErrUnexpectedEOF {
if cause != nil && !errors.Is(cause, io.EOF) && !errors.Is(cause, io.ErrUnexpectedEOF) {
c.logger.Printf("jsonrpc2: protocol error: %v\n", cause)
}

Expand Down
6 changes: 4 additions & 2 deletions handler_with_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package jsonrpc2

import (
"context"
"errors"
)

// HandlerWithError implements Handler by calling the func for each
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 3 additions & 1 deletion websocket/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package websocket

import (
"errors"
"io"

ws "github.com/gorilla/websocket"
Expand All @@ -28,7 +29,8 @@ func (t ObjectStream) WriteObject(obj interface{}) error {
// ReadObject implements jsonrpc2.ObjectStream.
func (t ObjectStream) ReadObject(v interface{}) error {
err := t.conn.ReadJSON(v)
if e, ok := err.(*ws.CloseError); ok {
var e *ws.CloseError
if errors.As(err, &e) {
if e.Code == ws.CloseAbnormalClosure && e.Text == io.ErrUnexpectedEOF.Error() {
// Suppress a noisy (but harmless) log message by
// unwrapping this error.
Expand Down
Loading