mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-06-17 12:43:18 +08:00
Refactor error handling
This commit is contained in:
@ -5,7 +5,6 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
E "github.com/bestnite/sub2clash/error"
|
||||
P "github.com/bestnite/sub2clash/model/proxy"
|
||||
)
|
||||
|
||||
@ -29,13 +28,13 @@ func (p *Hysteria2Parser) GetType() string {
|
||||
|
||||
func (p *Hysteria2Parser) Parse(proxy string) (P.Proxy, error) {
|
||||
if !hasPrefix(proxy, p.GetPrefixes()) {
|
||||
return P.Proxy{}, &E.ParseError{Type: E.ErrInvalidPrefix, Raw: proxy}
|
||||
return P.Proxy{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
|
||||
}
|
||||
|
||||
link, err := url.Parse(proxy)
|
||||
if err != nil {
|
||||
return P.Proxy{}, &E.ParseError{
|
||||
Type: E.ErrInvalidStruct,
|
||||
return P.Proxy{}, &ParseError{
|
||||
Type: ErrInvalidStruct,
|
||||
Message: "url parse error",
|
||||
Raw: proxy,
|
||||
}
|
||||
@ -50,24 +49,24 @@ func (p *Hysteria2Parser) Parse(proxy string) (P.Proxy, error) {
|
||||
query := link.Query()
|
||||
server := link.Hostname()
|
||||
if server == "" {
|
||||
return P.Proxy{}, &E.ParseError{
|
||||
Type: E.ErrInvalidStruct,
|
||||
return P.Proxy{}, &ParseError{
|
||||
Type: ErrInvalidStruct,
|
||||
Message: "missing server host",
|
||||
Raw: proxy,
|
||||
}
|
||||
}
|
||||
portStr := link.Port()
|
||||
if portStr == "" {
|
||||
return P.Proxy{}, &E.ParseError{
|
||||
Type: E.ErrInvalidStruct,
|
||||
return P.Proxy{}, &ParseError{
|
||||
Type: ErrInvalidStruct,
|
||||
Message: "missing server port",
|
||||
Raw: proxy,
|
||||
}
|
||||
}
|
||||
port, err := ParsePort(portStr)
|
||||
if err != nil {
|
||||
return P.Proxy{}, &E.ParseError{
|
||||
Type: E.ErrInvalidPort,
|
||||
return P.Proxy{}, &ParseError{
|
||||
Type: ErrInvalidPort,
|
||||
Raw: portStr,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user