Skip to content

Commit

Permalink
add error codes to create participant input validation errors (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwe authored Nov 20, 2024
1 parent 9b10ad8 commit ba2922c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/livekit/mediatransportutil/pkg/rtcconfig"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/redis"
"github.com/livekit/protocol/utils"
"github.com/livekit/protocol/utils/guid"
"github.com/livekit/psrpc"
lksdk "github.com/livekit/server-sdk-go/v2"

Expand Down Expand Up @@ -115,7 +115,7 @@ func NewConfig(confString string) (*Config, error) {
}

func (c *Config) Init() error {
c.NodeID = utils.NewGuid("NE_")
c.NodeID = guid.New("NE_")

if c.SIPPort == 0 {
c.SIPPort = DefaultSIPPort
Expand Down
19 changes: 9 additions & 10 deletions pkg/sip/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package sip

import (
"context"
"errors"
"fmt"
"log/slog"
"net/netip"
"strings"
Expand All @@ -31,6 +29,7 @@ import (
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/rpc"
"github.com/livekit/protocol/tracer"
"github.com/livekit/psrpc"
"github.com/livekit/sipgo"
"github.com/livekit/sipgo/sip"

Expand Down Expand Up @@ -132,25 +131,25 @@ func (c *Client) createSIPParticipant(ctx context.Context, req *rpc.InternalCrea
return nil, siperrors.ErrUnavailable
}
if req.CallTo == "" {
return nil, fmt.Errorf("call-to number must be set")
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "call-to number must be set")
} else if req.Address == "" {
return nil, fmt.Errorf("trunk adresss must be set")
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "trunk adresss must be set")
} else if req.Number == "" {
return nil, fmt.Errorf("trunk outbound number must be set")
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "trunk outbound number must be set")
} else if req.RoomName == "" {
return nil, fmt.Errorf("room name must be set")
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "room name must be set")
}
if strings.Contains(req.CallTo, "@") {
return nil, errors.New("call_to should be a phone number or SIP user, not a full SIP URI")
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "call_to should be a phone number or SIP user, not a full SIP URI")
}
if strings.HasPrefix(req.Address, "sip:") || strings.HasPrefix(req.Address, "sips:") {
return nil, errors.New("address must be a hostname without 'sip:' prefix")
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "address must be a hostname without 'sip:' prefix")
}
if strings.Contains(req.Address, "transport=") {
return nil, errors.New("address must not contain parameters; use transport field")
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "address must not contain parameters; use transport field")
}
if strings.ContainsAny(req.Address, ";=") {
return nil, errors.New("address must not contain parameters")
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "address must not contain parameters")
}
log := c.log
if req.ProjectId != "" {
Expand Down

0 comments on commit ba2922c

Please sign in to comment.