Skip to content

TW-5059: fix WrapError request ID false-match and classification gaps#85

Merged
qasim-nylas merged 1 commit into
mainfrom
tw-5059/fix-wrap-error-request-id-classification
May 15, 2026
Merged

TW-5059: fix WrapError request ID false-match and classification gaps#85
qasim-nylas merged 1 commit into
mainfrom
tw-5059/fix-wrap-error-request-id-classification

Conversation

@qasim-nylas
Copy link
Copy Markdown
Collaborator

Summary

  • Fix two bugs in WrapError where APIError instances with status 401/403/404 fell through to string-matching on err.Error(), which since PR TW-4937: surface API request ID in CLI error output #80 includes [request_id: ...] — a request ID containing "502" or "429" as a substring could misclassify the error, and all string-match paths silently dropped the request ID
  • Extend the structured switch to handle 401 (auth failed), 403 (permission denied), 404 (not found), and a default catch-all so every APIError is classified by status code with RequestID preserved
  • Remove redundant User-Agent header set in doJSONRequestInternalWithRetry (already set by doRequest/doRequestNoRetry)

Test plan

  • TestWrapError_RequestIDDoesNotFalseMatchStatusCode — regression test proving request IDs containing "502", "429", "500" don't cause misclassification
  • TestWrapError_APIErrorStatusClassification — expanded with 401, 403, 404 cases
  • TestWrapError_PropagatesRequestID — all status code paths carry request ID
  • TestWrapError_GenericForbiddenFallsThrough — generic 403 gets permission denied, not scope-specific suggestions
  • TestHTTPClient_UserAgent — User-Agent still sent on all requests after removing redundant set
  • make ci-full passes (4 pre-existing scheduler 404 failures unrelated to this change)

Related docs

APIError instances with status codes not handled by the structured
switch (401, 403, 404) fell through to string-matching on err.Error(),
which now includes [request_id: ...] from PR #80. A request ID
containing "502" or "429" as a substring could misclassify the error,
and all string-match paths silently dropped the request ID.

Extend the switch to cover 401, 403, 404, and a default catch-all so
every APIError is classified by status code with its RequestID
preserved. Remove redundant User-Agent set in doJSONRequestInternal.
@qasim-nylas qasim-nylas requested a review from AaronDDM May 15, 2026 11:11
@qasim-nylas qasim-nylas merged commit 7e85d9b into main May 15, 2026
6 checks passed
@qasim-nylas qasim-nylas deleted the tw-5059/fix-wrap-error-request-id-classification branch May 15, 2026 11:56
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.

2 participants