Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Feature/retryablehttp #40

Merged
merged 13 commits into from
Jan 7, 2019
Merged

Feature/retryablehttp #40

merged 13 commits into from
Jan 7, 2019

Conversation

GWeggemans
Copy link
Collaborator

No description provided.

@@ -30,7 +30,7 @@ describe('A Retryer', () => {

retryableMock.attempt = () => Promise.resolve(true);

const retryer = new Retryer(statsDMock, retryableMock, 2, 1, 1, 1);
const retryer = new Retryer(statsDMock, retryableMock, 2, 1, 1, 1, ['service:intershop']);
Copy link
Contributor

@ryreitsma ryreitsma Jan 2, 2019

Choose a reason for hiding this comment

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

It's not very readable to have arguments like this in a constructor. As a consumer of this code, I can't see what it does, what does 2,1,1,1 do?

Maybe have a look at using named parameters in this constructor? I think Typescript has a way to do this, would result in something like:

const retryer = new Retryer({statsD: statsDMock, retryable: retryableMock, maxAttempts: 2, minInterval: 1, maxInterval: 1, jitter: 1, defaultTags: ['service:intershop']});

I've seen that you can also set defaults in the constructor so you won't have to specify all of the arguments. I think most consumers of this constructor would be fine with having the intervals and jitter set to 1 by default

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I agree

Typescript does not support "real" named parameters in the constructor:
microsoft/TypeScript#467

When using an object like the example above, you can't use default constructor values anymore. I will play around looking nice solution.

Copy link
Collaborator Author

@GWeggemans GWeggemans Jan 3, 2019

Choose a reason for hiding this comment

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

image
Also, maybe webstorm is making me lazy :)
It adds the parameter name to these values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed


delete tags.body;

if (this.requestResult) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could refactor the tags method into less responsibilities. Perhaps adding a (private) validateRequestResult method underneath

Copy link
Contributor

Choose a reason for hiding this comment

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

Should still pass the tests of course


private isRetryable(requestResult: HTTPRequestResponse | Error): boolean {
if (requestResult instanceof Error) {
return requestResult.message !== 'Error: ESOCKETTIMEDOUT' &&
Copy link
Contributor

Choose a reason for hiding this comment

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

This is hard to read. Though I understand it's nice to do it in one go, some in between constants would make it more readable fore the next guy updating it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Improved it

@GWeggemans GWeggemans merged commit 0d6514f into master Jan 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants