Skip to content

fix: report the server's reason when it rejects messages - #112

Draft
rahul-mixpanel wants to merge 2 commits into
masterfrom
rahulraveendran-sdk-326-java-38-missing-token-produces
Draft

rahul-mixpanel wants to merge 2 commits into
masterfrom
rahulraveendran-sdk-326-java-38-missing-token-produces

Conversation

@rahul-mixpanel

@rahul-mixpanel rahul-mixpanel commented Nov 27, 2026 •

Copy link
Copy Markdown

Related to #38

Problem

When /track, /engage or /groups rejects a batch, MixpanelAPI always throws MixpanelServerException("Server refused to accept messages, they may be malformed."). The SDK never asks the server why, so a missing or null token (or any other rejection) gives the same vague message.

Fix

sendData now adds verbose=1 to the request, the way the Python, Ruby and Go SDKs already do. The server then answers with {"status":0,"error":"token, missing or empty"}, and the exception message carries that reason:

Server refused to accept messages: token, missing or empty

Compatibility:

  • The event/profile payload is unchanged; only the verbose=1 query parameter is added.
  • A plain 1 response is still accepted (e.g. a proxy that ignores verbose), as is the verbose {"status":1}.
  • Rejections still throw MixpanelServerException, and getBadDeliveryContents() still returns the rejected batch.
  • /import is unchanged; it has its own response handling.
  • When the server gives a reason, the exception message no longer contains "they may be malformed"; only code that matches on that text would notice. When no reason is given, the old message is kept.

Checked against the live API with an empty token: verbose=0 returns 0, verbose=1 returns {"error":"token, missing or empty","status":0} (both HTTP 200). /engage and /groups with an empty $token and verbose=1 likewise return HTTP 200 with {"error":"$token, missing or empty","status":0}.

Tests

  • testServerRejectionIncludesServerReason: local HTTP server that behaves like /track. Fails on master with the old "may be malformed" message and passes with the fix.
  • testServerAcceptsVerboseAndPlainSuccess: both success formats are accepted.
  • Full suite: 398 tests pass.

🤖 Generated with Claude Code

Request verbose responses from /track, /engage and /groups so a rejection
such as a missing token surfaces as "token, missing or empty" instead of
the generic "they may be malformed" message. Plain "1" responses are still
accepted, and the rejected batch is still attached to the exception.

Related to #38

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Nov 27, 2026

Copy link
Copy Markdown

SDK-326

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (2) · Last reviewed commit: "fix: keep cause when attaching batch; cl..." · Reviewed by Greptile

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant