Skip to content

fix: ResponseHandler.getResponse() returns OK after 401 (issue #107) - #109

Merged
hkarthik7 merged 2 commits into
hkarthik7:mainfrom
abhishekbagde:fix/107-workitemtypes-response-handler-overwrite
Jun 2, 2026
Merged

hkarthik7 merged 2 commits into
hkarthik7:mainfrom
abhishekbagde:fix/107-workitemtypes-response-handler-overwrite

Conversation

@abhishekbagde

@abhishekbagde abhishekbagde commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes a bug where ResponseHandler.getResponse().getStatusCode() returns OK instead of UNAUTHORIZED after a 401 response (e.g. calling workItemTypes().list() without a project in the credential).

Root cause: ErrorResponseHandler was building the 401 error message with:
context.request().getRequestUri() calls LocationService.getInstance().getLocation(), which creates a fresh instance (empty cache) and fires an OPTIONS HTTP request to discover the resource area. That OPTIONS call goes through the full response pipeline, causing ApiResponseHandler to overwrite ResponseHandler.apiResponse with the 200 OK OPTIONS response — hiding the real 401 from the caller.

Fix: Use context.response().request().uri() instead — reads the URI directly from the already-sent HttpResponse with no side effects.

PR Checklist

  • Added help (comment on the fix explains the why)
  • Added unit test (shouldRetainUnauthorizedStatusInResponseHandlerWhenProjectIsAbsent in WorkItemTrackingRequestBuilderTest)
  • Updated Change log (CHANGELOG.md — added 7.0.1 section)

…ik7#107)

When ErrorResponseHandler built the UnAuthorizedException message it called
context.request().getRequestUri() on the RequestInformation object.
That method calls LocationService.getInstance().getLocation(), which creates a
*fresh* LocationService (empty cache) and makes an OPTIONS request to discover
the resource area. That OPTIONS call goes through the full response pipeline,
causing ApiResponseHandler to overwrite ResponseHandler.apiResponse with the
200 OK OPTIONS response — hiding the real 401 from the caller.

Fix: replace context.request().getRequestUri() with
context.response().request().uri(), which reads the URI directly from the
already-sent HttpResponse with no side effects.

Regression test added in WorkItemTrackingRequestBuilderTest:
shouldRetainUnauthorizedStatusInResponseHandlerWhenProjectIsAbsent
@hkarthik7 hkarthik7 self-assigned this Jun 2, 2026
@hkarthik7 hkarthik7 added the bug Something isn't working label Jun 2, 2026

@hkarthik7 hkarthik7 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hkarthik7
hkarthik7 merged commit 1da34f6 into hkarthik7:main Jun 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants