Skip to content

Submit handles non 2xx responses#793

Merged
kytrinyx merged 2 commits intoexercism:masterfrom
jdsutherland:submit-handles-non2xx
Mar 8, 2019
Merged

Submit handles non 2xx responses#793
kytrinyx merged 2 commits intoexercism:masterfrom
jdsutherland:submit-handles-non2xx

Conversation

@jdsutherland
Copy link
Copy Markdown
Contributor

@jdsutherland jdsutherland commented Jan 11, 2019

Previously, 404s silently continue to misleading success output. This change throws an error for all non 2xx responses.

Closes #790.

cmd/submit.go Outdated
}

if resp.StatusCode < 200 || resp.StatusCode > 299 {
return fmt.Errorf("submission unsuccessful (%s)", resp.Status)
Copy link
Copy Markdown
Contributor Author

@jdsutherland jdsutherland Jan 11, 2019

Choose a reason for hiding this comment

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

I'm guessing we want this to be more useful; what should this say?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The API should respond with {"error": {"type": "some_value", "message": "A human-readable message"}} in the case of an error. Let's use the message if it has something available in it, otherwise let's use the default that you have here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually, you wrote code that fixed it. I've extracted that here:
#814

@kytrinyx
Copy link
Copy Markdown
Member

kytrinyx commented Mar 3, 2019

@jdsutherland Now that we've gotten some of the helpers into master, would it make sense to rework this to use the helpers?

@jdsutherland jdsutherland force-pushed the submit-handles-non2xx branch 2 times, most recently from 1c3d8a9 to 4b23582 Compare March 4, 2019 01:59
Previously, 404s silently continue to misleading success output
@jdsutherland jdsutherland force-pushed the submit-handles-non2xx branch from 4b23582 to 10aea95 Compare March 4, 2019 02:06
@jdsutherland
Copy link
Copy Markdown
Contributor Author

jdsutherland commented Mar 8, 2019

This is ready for another look.

Copy link
Copy Markdown
Member

@kytrinyx kytrinyx left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks for your patience here 💙

assert.Regexp(t, "test error", err.Error())
}

func TestHandleErrorResponse(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for adding this test!

@kytrinyx kytrinyx merged commit 89e80c4 into exercism:master Mar 8, 2019
@jdsutherland jdsutherland deleted the submit-handles-non2xx branch March 8, 2019 05:36
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