Skip to content

Commit b1b7ca6

Browse files
iibaranov-IGJoTurk
authored andcommitted
Return typed TURN errors from TCP connect
1 parent 70eb89e commit b1b7ca6

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎internal/client/tcp_alloc.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ func (a *TCPAllocation) Connect(peer net.Addr) (proto.ConnectionID, error) {
113113
if res.Type.Class == stun.ClassErrorResponse {
114114
var code stun.ErrorCodeAttribute
115115
if err = code.GetFrom(res); err == nil {
116-
return 0, fmt.Errorf("%s (error %s)", res.Type, code) //nolint // dynamic errors
116+
return 0, &stun.TurnError{
117+
StunMessageType: res.Type,
118+
ErrorCodeAttr: code,
119+
}
117120
}
118121

119122
return 0, fmt.Errorf("%s", res.Type) //nolint // dynamic errors

‎internal/client/tcp_conn_test.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package client
55

66
import (
77
"context"
8+
"errors"
89
"net"
910
"testing"
1011
"time"
@@ -115,7 +116,9 @@ func TestTCPConn(t *testing.T) {
115116
}
116117

117118
_, err = alloc.Connect(addr)
118-
assert.ErrorContains(t, err, "Connect error response", "error 400")
119+
var turnErr *stun.TurnError
120+
assert.True(t, errors.As(err, &turnErr))
121+
assert.Equal(t, stun.CodeBadRequest, turnErr.ErrorCodeAttr.Code)
119122
})
120123

121124
t.Run("SetDeadline()", func(t *testing.T) {

0 commit comments

Comments
 (0)
⌂ 换网址