Skip to content

Commit

Permalink
fix: type assertion on errors fails on wrapped errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbekhen committed Aug 28, 2023
1 parent 4ae1a4e commit 6b9731b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package proxy

import (
"errors"
"io"
"log"
"net"
Expand Down Expand Up @@ -119,13 +120,16 @@ func extractClientAddress(clientAddr string, source interface{}) (string, string
if host, port, err := net.SplitHostPort(clientAddr); err == nil {
clientIP = host
clientPort = port
} else if addrErr, ok := err.(*net.AddrError); ok {
switch addrErr.Err {
case "missing port in address":
fallthrough
case "too many colons in address":
clientIP = clientAddr
default:
} else {
var addrErr *net.AddrError
if errors.As(err, &addrErr) {
switch addrErr.Err {
case "missing port in address":
fallthrough
case "too many colons in address":
clientIP = clientAddr
default:
}
}
}
}
Expand Down

0 comments on commit 6b9731b

Please sign in to comment.