chenhg5/cc-connect · error
max: edit message: HTTP %d: %s
Error message
max: edit message: HTTP %d: %s
What it means
This error is returned by Platform.UpdateMessage when the MAX Bot API responds to a message-edit request with a non-200 HTTP status. The library wraps the status code and up to 512 bytes of the response body so the caller can see exactly why the edit was rejected. It means the API call itself succeeded at the transport level but the server refused the edit.
Source
Thrown at platform/max/max.go:524
}
req, err := http.NewRequestWithContext(ctx, http.MethodPut, p.apiBase+"/messages", bytes.NewReader(data))
if err != nil {
return err
}
p.setAuth(req)
q := req.URL.Query()
q.Set("message_id", rctx.messageID)
req.URL.RawQuery = q.Encode()
req.Header.Set("Content-Type", "application/json")
resp, err := p.client.Do(req)
if err != nil {
return fmt.Errorf("max: edit message: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
respBody, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
return fmt.Errorf("max: edit message: HTTP %d: %s", resp.StatusCode, respBody)
}
return nil
}
// uploadAttachment performs the two-step MAX upload: request an upload URL from
// /uploads?type=<kind>, then POST the binary as multipart/form-data field "data"
// to that URL. Returns the token to embed in a subsequent /messages attachment.
func (p *Platform) uploadAttachment(ctx context.Context, kind string, data []byte, filename string) (string, error) {
if len(data) == 0 {
return "", fmt.Errorf("empty attachment data")
}
// Use a 5-minute context AND a dedicated http.Client with a matching Timeout.
// p.client has a 35 s Timeout which fires independently of the context deadline
// and would abort large CDN uploads before the context expires.
uploadCtx, cancel := context.WithTimeout(ctx, attachmentUploadTO)
defer cancel()
urlReq, err := http.NewRequestWithContext(uploadCtx, http.MethodPost, p.apiBase+"/uploads", nil)View on GitHub (pinned to 4000b2338a)
Solutions
- Log respBody and status from the error to identify the exact API rejection reason
- Verify the bot token is valid and has permission for the target chat
- Confirm the message ID exists and was not deleted before editing
- If status is 429, add backoff/retry; if 5xx, retry with exponential backoff
- Update the MAX Bot API client assumptions if the API contract changed
Example fix
// before
if err := p.UpdateMessage(ctx, chatID, msgID, newText); err != nil { return err }
// after
if err := p.UpdateMessage(ctx, chatID, msgID, newText); err != nil {
var httpErr interface{ Error() string }
_ = httpErr
slog.Warn("max: edit failed, falling back to new message", "err", err)
_, err = p.Reply(ctx, chatID, newText)
return err
} Defensive patterns
Strategy: try-catch
Validate before calling
if msgID == "" || newText == "" { return errors.New("max: message id and text required before edit") } Try / catch
if err := p.UpdateMessage(ctx, chatID, msgID, text); err != nil {
if strings.Contains(err.Error(), "HTTP 429") || strings.Contains(err.Error(), "HTTP 5") {
// retry with backoff
} else {
return fmt.Errorf("edit message: %w", err)
}
} Prevention
- Check message existence before editing
- Refresh bot tokens before expiry
- Distinguish retryable (429/5xx) from permanent (4xx) statuses in error handling
- Log the response body embedded in the error for diagnosis
When it happens
Trigger: Calling UpdateMessage (or the max.EditMessage path) when the MAX API returns e.g. 400 (malformed message ID/text), 401/403 (bad or expired bot token), 404 (message ID no longer exists or belongs to another chat), or 429/5xx from the server.
Common situations: Editing a message after the chat/message was deleted; using a stale or revoked bot token; passing a message ID obtained from a different chat; MAX API rate limiting during heavy streaming edits; transient MAX server errors (5xx).
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- upload url: HTTP %d: %s
- upload url: empty url in response
- cdn upload: HTTP %d: %s
- poll: HTTP %d: %s
- usage endpoint returned status %d: %s
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/78203e5b73defee5.
Report an issue: GitHub.