add bitrix support
This commit is contained in:
1 parent
747f8f2312
commit
5690cf58a9
62 files changed
+4098
-1053
No files matched your search
+46
-7
@@ -1,14 +1,22 @@
|
||||
package common
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
StatusReady = "READY"
|
||||
StatusConnecting = "CONNECTING"
|
||||
StatusReconnecting = "RECONNECTING"
|
||||
StatusTunnelConnected = "TUNNEL_CONNECTED"
|
||||
StatusTunnelLost = "TUNNEL_LOST"
|
||||
StatusError = "ERROR"
|
||||
StatusReady = "READY"
|
||||
StatusConnecting = "CONNECTING"
|
||||
StatusReconnecting = "RECONNECTING"
|
||||
StatusTunnelConnected = "TUNNEL_CONNECTED"
|
||||
StatusTunnelLost = "TUNNEL_LOST"
|
||||
StatusError = "ERROR"
|
||||
)
|
||||
|
||||
const (
|
||||
AuthErrorInvalidCredentials = "INVALID_CREDENTIALS"
|
||||
AuthErrorSessionExpired = "SESSION_EXPIRED"
|
||||
)
|
||||
|
||||
func EmitStatus(status string) {
|
||||
@@ -18,3 +26,34 @@ func EmitStatus(status string) {
|
||||
func EmitStatusError(msg string) {
|
||||
fmt.Printf("STATUS:%s:%s\n", StatusError, msg)
|
||||
}
|
||||
|
||||
func EmitAuthError(kind string) {
|
||||
fmt.Printf("STATUS:AUTH_ERROR:%s\n", kind)
|
||||
}
|
||||
|
||||
func looksLikeInvalidCreds(msg string) bool {
|
||||
return strings.Contains(msg, `"code":1086`) ||
|
||||
strings.Contains(msg, "Invalid credentials") ||
|
||||
strings.Contains(msg, "login rejected")
|
||||
}
|
||||
|
||||
func looksLikeSessionExpired(msg string) bool {
|
||||
return strings.Contains(msg, "status 401") ||
|
||||
strings.Contains(msg, "UnauthorizedError") ||
|
||||
strings.Contains(msg, `"error":"unauthorized`) ||
|
||||
strings.Contains(msg, "empty access_token") ||
|
||||
strings.Contains(msg, "empty VK token")
|
||||
}
|
||||
|
||||
func EmitAuthErrorFor(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
msg := err.Error()
|
||||
switch {
|
||||
case looksLikeInvalidCreds(msg):
|
||||
EmitAuthError(AuthErrorInvalidCredentials)
|
||||
case looksLikeSessionExpired(msg):
|
||||
EmitAuthError(AuthErrorSessionExpired)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user