Skip to content

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

Open
abhishekbagde wants to merge 1 commit into
hkarthik7:mainfrom
abhishekbagde:fix/107-workitemtypes-response-handler-overwrite
Open

fix: ResponseHandler.getResponse() returns OK after 401 (issue #107)#109
abhishekbagde wants to merge 1 commit into
hkarthik7:mainfrom
abhishekbagde:fix/107-workitemtypes-response-handler-overwrite

Conversation

@abhishekbagde
Copy link
Copy Markdown

@abhishekbagde abhishekbagde commented Apr 25, 2026

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
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