Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
package imclient
import (
"fmt"
"net/http"
"strings"
)
const sessionExpiredCode = 401
type APIError struct {
StatusCode int
Code int
Message string
Body []byte
}
func (e *APIError) Error() string {
if e == nil {
return ""
}
if e.Code != 0 {
return fmt.Sprintf("im api error: status=%d code=%d message=%s", e.StatusCode, e.Code, e.Message)
}
return fmt.Sprintf("im api error: status=%d message=%s", e.StatusCode, e.Message)
}
func IsSessionExpired(err error) bool {
apiErr, ok := err.(*APIError)
if !ok || apiErr == nil {
return false
}
if apiErr.Code == sessionExpiredCode || apiErr.StatusCode == http.StatusUnauthorized {
return true
}
msg := strings.ToLower(apiErr.Message)
return strings.Contains(msg, "session has expired") ||
strings.Contains(msg, "log in again") ||
strings.Contains(msg, "token expired") ||
strings.Contains(msg, "token invalid")
}