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

Submit handles non 2xx responses #793

Merged
merged 2 commits into from
Mar 8, 2019

Conversation

jdsutherland
Copy link
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
@@ -261,6 +261,10 @@ func (s *submitCmdContext) submit(metadata *workspace.ExerciseMetadata, docs []w
return fmt.Errorf(jsonErrBody.Error.Message)
}

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

jdsutherland commented Mar 8, 2019

This is ready for another look.

Copy link
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 💙

@@ -611,6 +611,44 @@ func TestSubmitServerErr(t *testing.T) {
assert.Regexp(t, "test error", err.Error())
}

func TestHandleErrorResponse(t *testing.T) {
Copy link
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