fix: ResponseHandler.getResponse() returns OK after 401 (issue #107)#109
Open
abhishekbagde wants to merge 1 commit into
Open
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a bug where
ResponseHandler.getResponse().getStatusCode()returnsOKinstead ofUNAUTHORIZEDafter a 401 response (e.g. callingworkItemTypes().list()without a project in the credential).Root cause:
ErrorResponseHandlerwas 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