Skip to content

Commit 10aea95

Browse files
committed
Use api error helper
1 parent 3353734 commit 10aea95

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

cmd/submit.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"io"
88
"mime/multipart"
9-
"net/http"
109
"os"
1110
"path/filepath"
1211

@@ -268,12 +267,8 @@ func (s *submitCmdContext) submit(metadata *workspace.ExerciseMetadata, docs []w
268267
}
269268
defer resp.Body.Close()
270269

271-
if resp.StatusCode == http.StatusBadRequest {
272-
return decodedAPIError(resp)
273-
}
274-
275270
if resp.StatusCode < 200 || resp.StatusCode > 299 {
276-
return fmt.Errorf("submission unsuccessful (%s)", resp.Status)
271+
return decodedAPIError(resp)
277272
}
278273

279274
bb := &bytes.Buffer{}

cmd/submit_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ func TestSubmitServerErr(t *testing.T) {
611611
assert.Regexp(t, "test error", err.Error())
612612
}
613613

614-
func TestHandle404Response(t *testing.T) {
614+
func TestHandleErrorResponse(t *testing.T) {
615615
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
616616
w.WriteHeader(404)
617617
})
@@ -646,10 +646,9 @@ func TestHandle404Response(t *testing.T) {
646646
}
647647

648648
err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), files)
649-
if assert.Error(t, err) {
650-
assert.Contains(t, err.Error(), "unsuccessful")
651-
}
649+
assert.Error(t, err)
652650
}
651+
653652
func TestSubmissionNotConnectedToRequesterAccount(t *testing.T) {
654653
submittedFiles := map[string]string{}
655654
ts := fakeSubmitServer(t, submittedFiles)

0 commit comments

Comments
 (0)