Skip to content

Commit

Permalink
better error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed Dec 29, 2022
1 parent e2fbd4e commit af0b1a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions internal/stun.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ func (s *Stun) GetErrorString() string {
for _, a := range s.Attributes {
if a.Type == AttrErrorCode {
attrError := ParseError(a.Value)
// update error text if server did not provide one
if len(strings.TrimSpace(attrError.ErrorText)) == 0 {
if tmp, ok := StunErrorNames[attrError.ErrorCode]; ok {
attrError.ErrorText = tmp
} else if tmp, ok := TurnErrorNames[attrError.ErrorCode]; ok {
attrError.ErrorText = tmp
} else if tmp, ok := TurnTCPErrorNames[attrError.ErrorCode]; ok {
attrError.ErrorText = tmp
} else {
attrError.ErrorText = "Invalid Error"
}
}
return fmt.Sprintf("Error %d: %s", attrError.ErrorCode, attrError.ErrorText)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/types_stun.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ const (
)

// nolint:deadcode,varcheck,unused
var errorNames = map[ErrorCode]string{
var StunErrorNames = map[ErrorCode]string{
ErrorTryAlternate: "Try Alternate",
ErrorBadRequest: "Bad Request",
ErrorUnauthorized: "Unauthorized",
Expand Down

0 comments on commit af0b1a6

Please sign in to comment.