proper error handling
cleanup files
This commit is contained in:
+10
-16
@@ -5,9 +5,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||||
@@ -57,20 +56,15 @@ func Dial(rawURL string) (*Client, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
reader := bufio.NewReader(conn)
|
resp, _ := http.ReadResponse(bufio.NewReader(conn), nil)
|
||||||
statusLine, _ := reader.ReadString('\n')
|
if resp != nil {
|
||||||
parts := strings.SplitN(statusLine, " ", 3)
|
switch resp.StatusCode {
|
||||||
if len(parts) >= 2 {
|
case 204:
|
||||||
statusCode, err := strconv.Atoi(parts[1])
|
conn.Close()
|
||||||
if err == nil {
|
return nil, errors.New("DoorBird user has no api permission")
|
||||||
if statusCode == 204 {
|
case 503:
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return nil, errors.New("DoorBird user has no api permission")
|
return nil, errors.New("DoorBird device is busy")
|
||||||
}
|
|
||||||
if statusCode == 503 {
|
|
||||||
conn.Close()
|
|
||||||
return nil, errors.New("DoorBird device is busy")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package doorbird
|
|
||||||
|
|
||||||
import "sync"
|
|
||||||
|
|
||||||
var backchannelMu sync.Mutex
|
|
||||||
Reference in New Issue
Block a user