Skip to content

Commit ba2922c

Browse files
authored
add error codes to create participant input validation errors (#230)
1 parent 9b10ad8 commit ba2922c

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

pkg/config/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/livekit/mediatransportutil/pkg/rtcconfig"
2828
"github.com/livekit/protocol/logger"
2929
"github.com/livekit/protocol/redis"
30-
"github.com/livekit/protocol/utils"
30+
"github.com/livekit/protocol/utils/guid"
3131
"github.com/livekit/psrpc"
3232
lksdk "github.com/livekit/server-sdk-go/v2"
3333

@@ -115,7 +115,7 @@ func NewConfig(confString string) (*Config, error) {
115115
}
116116

117117
func (c *Config) Init() error {
118-
c.NodeID = utils.NewGuid("NE_")
118+
c.NodeID = guid.New("NE_")
119119

120120
if c.SIPPort == 0 {
121121
c.SIPPort = DefaultSIPPort

pkg/sip/client.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ package sip
1616

1717
import (
1818
"context"
19-
"errors"
20-
"fmt"
2119
"log/slog"
2220
"net/netip"
2321
"strings"
@@ -31,6 +29,7 @@ import (
3129
"github.com/livekit/protocol/logger"
3230
"github.com/livekit/protocol/rpc"
3331
"github.com/livekit/protocol/tracer"
32+
"github.com/livekit/psrpc"
3433
"github.com/livekit/sipgo"
3534
"github.com/livekit/sipgo/sip"
3635

@@ -132,25 +131,25 @@ func (c *Client) createSIPParticipant(ctx context.Context, req *rpc.InternalCrea
132131
return nil, siperrors.ErrUnavailable
133132
}
134133
if req.CallTo == "" {
135-
return nil, fmt.Errorf("call-to number must be set")
134+
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "call-to number must be set")
136135
} else if req.Address == "" {
137-
return nil, fmt.Errorf("trunk adresss must be set")
136+
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "trunk adresss must be set")
138137
} else if req.Number == "" {
139-
return nil, fmt.Errorf("trunk outbound number must be set")
138+
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "trunk outbound number must be set")
140139
} else if req.RoomName == "" {
141-
return nil, fmt.Errorf("room name must be set")
140+
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "room name must be set")
142141
}
143142
if strings.Contains(req.CallTo, "@") {
144-
return nil, errors.New("call_to should be a phone number or SIP user, not a full SIP URI")
143+
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "call_to should be a phone number or SIP user, not a full SIP URI")
145144
}
146145
if strings.HasPrefix(req.Address, "sip:") || strings.HasPrefix(req.Address, "sips:") {
147-
return nil, errors.New("address must be a hostname without 'sip:' prefix")
146+
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "address must be a hostname without 'sip:' prefix")
148147
}
149148
if strings.Contains(req.Address, "transport=") {
150-
return nil, errors.New("address must not contain parameters; use transport field")
149+
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "address must not contain parameters; use transport field")
151150
}
152151
if strings.ContainsAny(req.Address, ";=") {
153-
return nil, errors.New("address must not contain parameters")
152+
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "address must not contain parameters")
154153
}
155154
log := c.log
156155
if req.ProjectId != "" {

0 commit comments

Comments
 (0)