Skip to content

Commit e96e02a

Browse files
refactor: replace fmt.Errorf with MessageTooBigError
1 parent 91013c1 commit e96e02a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

read.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ import (
1717
"github.com/coder/websocket/internal/util"
1818
)
1919

20+
type MessageTooBigError struct {
21+
Limit int64
22+
}
23+
24+
func (e MessageTooBigError) Error() string {
25+
return fmt.Sprintf("read limited at %v bytes", e.Limit)
26+
}
27+
2028
// Reader reads from the connection until there is a WebSocket
2129
// data message to be read. It will handle ping, pong and close frames as appropriate.
2230
//
@@ -520,7 +528,7 @@ func (lr *limitReader) Read(p []byte) (int, error) {
520528
}
521529

522530
if lr.n == 0 {
523-
err := fmt.Errorf("read limited at %v bytes", lr.limit.Load())
531+
err := MessageTooBigError{Limit: lr.limit.Load()}
524532
lr.c.writeError(StatusMessageTooBig, err)
525533
return 0, err
526534
}

0 commit comments

Comments
 (0)