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

Expose response HTTP status code in errors #52

Merged
merged 3 commits into from
Sep 28, 2016

Conversation

seh
Copy link
Contributor

@seh seh commented Sep 27, 2016

For various operations involving HTTP requests against the Eureka server, allow callers to interpret surfaced failures by way of inspecting the HTTP response's status code.

This proposal is a subset of the preceding #47, also intended to address #45. Rather than fargo interpreting what the server's responses mean in the context of the attempted operation, we leave that interpretation open to callers.

Copy link
Contributor

@damtur damtur left a comment

Choose a reason for hiding this comment

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

I like that approach :). I've had few minor comments. Please see if you agree on them. I think this will be The solution. Thank you very much for iterating this over with me.

)

func shouldNotBearAnHTTPStatusCode(actual interface{}, expected ...interface{}) string {
if code, present := fargo.HTTPResponseStatusCode(actual.(error)); present {
return fmt.Sprintf("Expected: no HTTP status code\nActual: %d", code)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why tabs here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I misinterpreted what I saw here in the assertion failure messages used by GoConvey, which I was trying to imitate. I'll fix it, aligning the fields with spaces instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ Done.

)

type unsuccessfulHTTPResponse struct {
statusCode int
Copy link
Contributor

Choose a reason for hiding this comment

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

I would unify order with string output. Maybe message prefix first and rcode second?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote the struct in order from most important to least important, from required to optional, thinking that the response code is the type's _raison d'être _. I tried to keep the string format consistent with the rest of fargo's error messages. I don't think you're advocating changing the string format.

I could swap the field order. I just wanted you to know that its current arrangement was a deliberate choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please take a look at commit 4f48c58, in which I make sure to treat the message prefix as optional. Given that, let me know if you'd still prefer the field order to be swapped.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. If you feel it's more appropriate leave it. I was just feeling that's it might look better when creating new error to have message first, so it would be similar to printf function. I'll leave decision to you. Thanks for clarifying.

code, present := HTTPResponseStatusCode(test.input)
if present {
if !test.present {
t.Errorf("input %v: want absent, got code %d", test.input, code)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please do those tests using Convey. (see other test files for guideline)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ Done.

seh added 3 commits September 28, 2016 10:44
For various operations involving HTTP requests against the Eureka
server, allow callers to interpret surfaced failures by way of
inspecting the HTTP response's status code.
@seh seh force-pushed the expose-http-status-code-in-errors branch from c913d16 to 648f74e Compare September 28, 2016 14:45
Copy link
Contributor

@damtur damtur left a comment

Choose a reason for hiding this comment

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

This is ready to go imo. @seh is there anything you want to add here or you are happy with me merging it?

@seh
Copy link
Contributor Author

seh commented Sep 28, 2016

I'm happy enough with it. I'm going to implement some of #47 on the caller side to see if any additional helper functions emerge that are worth sharing, but I understand your goal of keeping the surface area of fargo small.

@damtur damtur merged commit 14ced46 into hudl:master Sep 28, 2016
@seh seh deleted the expose-http-status-code-in-errors branch September 28, 2016 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants