Skip to content

Conversation

@Technoboy-
Copy link
Contributor

Motivation

When returning a 404 error using http-lookup, it doesn't prompt the correct message to user. below is a demo:

@Test
public void testHttpLookupWithNotFoundError() throws Exception {
     # Try to create a topic before namespace is created
     pulsarClient.newProducer().topic("unknownTenant/unknownNamespace/testNamespaceNotFound").create();
}

It will throw :

org.apache.pulsar.client.api.PulsarClientException$NotFoundException: Not found: Not Found

In this case, we should return Not found: Namespace not found.

The root cause is : when HTTP lookup with 404, we get the message from StatusText.

if (response2.getStatusCode() != HttpURLConnection.HTTP_OK) {
log.warn("[{}] HTTP get request failed: {}", requestUrl, response2.getStatusText());
Exception e;
if (response2.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
e = new NotFoundException("Not found: " + response2.getStatusText());
} else {
e = new PulsarClientException("HTTP get request failed: " + response2.getStatusText());
}
future.completeExceptionally(e);
return;
}

But we only set status,no statusText in RestException:

public RestException(int code, String message) {
super(message, Response.status(code).entity(new ErrorData(message)).type(MediaType.APPLICATION_JSON).build());
}

Documentation

  • no-need-doc

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Mar 14, 2022
Copy link
Member

@nodece nodece left a comment

Choose a reason for hiding this comment

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

LGTM

@codelipenghui codelipenghui added this to the 2.11.0 milestone Mar 15, 2022
@codelipenghui codelipenghui merged commit 9a88508 into apache:master Mar 15, 2022
codelipenghui pushed a commit that referenced this pull request Mar 18, 2022
@codelipenghui codelipenghui added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Mar 18, 2022
codelipenghui pushed a commit that referenced this pull request Mar 18, 2022
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Mar 18, 2022
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Mar 18, 2022
codelipenghui pushed a commit that referenced this pull request Apr 19, 2022
@Technoboy- Technoboy- deleted the fix-restexception branch August 10, 2022 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants