feat: enhance Safew error handling and polling mechanism

- Added error_msg field to safewAPIResponse for better error descriptions.
- Updated safewErrorDescription function to include error_msg in the output.
- Introduced a new test to verify that error messages are included in Safew error descriptions.
- Improved the polling mechanism in the Watcher to handle conflicts and ensure no overlapping polls occur.
This commit is contained in:
2026-08-15 01:07:01 +08:00
parent bd8a9ff96d
commit e369f398d8
4 changed files with 201 additions and 28 deletions
+7
View File
@@ -99,6 +99,13 @@ func TestPollGroupChatsSuccess(t *testing.T) {
}
}
func TestSafewErrorDescriptionIncludesErrorMsg(t *testing.T) {
got := safewErrorDescription([]byte(`{"ok":false,"description":"BAD_REQUEST","error_msg":"Conflict: terminated by other getUpdates request"}`))
if !strings.Contains(got, "Conflict") {
t.Fatalf("got %q, want error_msg", got)
}
}
func TestPollGroupChatsUnauthorized(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusUnauthorized)