Skip to content

Closing response body on RateLimitException#175

Merged
lbalmaceda merged 4 commits intoauth0:masterfrom
j-m-x:connection-leak-on-rate-limit-exception
Dec 3, 2018
Merged

Closing response body on RateLimitException#175
lbalmaceda merged 4 commits intoauth0:masterfrom
j-m-x:connection-leak-on-rate-limit-exception

Conversation

@j-m-x
Copy link
Copy Markdown
Contributor

@j-m-x j-m-x commented Nov 14, 2018

References #174 #

response = client.newCall(request).execute();
try (Response response = client.newCall(request).execute()) {
return parseResponse(response);
} catch (APIException e) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be Auth0Exception instead? Given that APIException is a subclass, people could later try/catch or ask what instanceof is the exception they receive and cast that to a APIException or read it as Auth0Exception. What are your thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right, will do.

Copy link
Copy Markdown
Contributor Author

@j-m-x j-m-x Dec 2, 2018

Choose a reason for hiding this comment

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

Your comment got me thinking and you're very right. This not only is better for the user of this client, but it actually was a bug. If an exception of type Auth0Exception was thrown, it would pass through the APIException catch and be caught by the IOException catch where it got wrapped in an extra Auth0Exception with the message Failed to execute request. Changing the first catch to Auth0Exception fixes this. I realised this a little late, but in a second commit I improvement the tests a bit to prove this.

return createRateLimitException(response);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can this diff be removed?

Copy link
Copy Markdown
Contributor Author

@j-m-x j-m-x Dec 2, 2018

Choose a reason for hiding this comment

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

Shouldn't have been there, will do.

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class BaseRequestTest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a FIXME comment at the class level pointing to the link you shared in the issue. My idea here is that in the future when they let users use this feature programmatically, we can come back to this code and fix it. Because today it seems enabling this extension is affecting the whole tests folder and not just a single class. https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2#mock-the-unmockable-opt-in-mocking-of-final-classesmethods

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea, will do.

response = Mockito.mock(Response.class);

call = Mockito.mock(Call.class);
Mockito.when(call.execute()).thenReturn(response);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

try statically importing this Mockito methods so you don't repeat Mockito. every time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bad habit of mine, will do.

@lbalmaceda lbalmaceda added this to the v1-Next milestone Dec 3, 2018
Copy link
Copy Markdown
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

Thanks (again!) for the time you've invested in this 🎉

@lbalmaceda lbalmaceda merged commit 5636f84 into auth0:master Dec 3, 2018
@j-m-x
Copy link
Copy Markdown
Contributor Author

j-m-x commented Dec 3, 2018

No problem, thanks for the constructive feedback and quick replies 🤘

@j-m-x j-m-x deleted the connection-leak-on-rate-limit-exception branch December 3, 2018 18:48
@lbalmaceda lbalmaceda modified the milestones: v1-Next, 1.10.0 Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants