Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/build integer response #18

Merged
merged 4 commits into from
May 14, 2018

Conversation

martinda
Copy link
Collaborator

This PR is to fix issue #16 .

This PR implements a new return type for endpoints returning an integer value. The new return type is IntegerResponse, and it is an integer encapsulated in an object that can also carries error information.

@cdancy cdancy self-assigned this May 11, 2018
@cdancy cdancy added this to the v0.0.10 milestone May 11, 2018
return 0;
errors.add(Error.create("No context",
"No queue item Location header could be found despite getting a valid HTTP response.",
"None"));
Copy link
Owner

Choose a reason for hiding this comment

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

Lets take the Error.create call outside and do something like:

final Error error = Error.create(null,
    "No queue item Location header could be found despite getting a valid HTTP response.", 
    NumberFormatException.class.getCanonicalName());
List<Error> errors = Lists.newArrayList(error);
return IntegerResponse.create(null, errors);

I'd prefer to delay the creation of the list until the last possible minute as this is an exceptional case. In the code further above lets just pass a null like so:

        return IntegerResponse.create(Integer.valueOf(matcher.group(1)), null);

import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.io.CharStreams;
Copy link
Owner

Choose a reason for hiding this comment

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

Are these imports needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will fix this.

@cdancy
Copy link
Owner

cdancy commented May 11, 2018

Few comments to address but all-in-all it looks good. Thanks for taking this work on.

Copy link
Collaborator Author

@martinda martinda left a comment

Choose a reason for hiding this comment

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

Sorry I am a bit confused about the review process on github... I will click the submit review button to see what happens.

return 0;
errors.add(Error.create("No context",
"No queue item Location header could be found despite getting a valid HTTP response.",
"None"));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@cdancy, in creating this error, is it possible to have the original context (the POST)?

Copy link
Owner

Choose a reason for hiding this comment

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

@martinda whatever is in the httpResponse is really all we have to work with. What were you thinknig?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@cdancy I was thinking of printing the HTTP response, in case it might give a hint to the user.

import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.io.CharStreams;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops!

if (url != null) {
Matcher matcher = pattern.matcher(url);
if (matcher.find() && matcher.groupCount() == 1) {
return Integer.valueOf(matcher.group(1));
return IntegerResponse.create(Integer.valueOf(matcher.group(1)), errors);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the code further above lets just pass a null like so:

   return IntegerResponse.create(Integer.valueOf(matcher.group(1)), null);

I was trying to apply the same approach as in the Bitbucket Rest Understanding Error objects where the error object is never null so it can always be easily checked.

Copy link
Owner

Choose a reason for hiding this comment

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

That's fair but lets let the underlying process take care of that instead of aggressively creating it up front.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now I get it, we let IntegerResponse convert null to an empty list.

import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.io.CharStreams;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will fix this.

@martinda martinda force-pushed the feature/build-integer-response branch from 795b2d0 to 615f80f Compare May 14, 2018 02:21
@cdancy
Copy link
Owner

cdancy commented May 14, 2018

@martinda LGTM. Anything else you want to do here or are we ready to merge?

@martinda
Copy link
Collaborator Author

@cdancy I am ready to merge.

@cdancy cdancy merged commit 961fa27 into cdancy:master May 14, 2018
@cdancy
Copy link
Owner

cdancy commented May 14, 2018

Thanks again @martinda !

@martinda martinda deleted the feature/build-integer-response branch August 5, 2021 03:57
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