@@ -3,6 +3,7 @@ package api
33import (
44 "encoding/json"
55 "fmt"
6+ "strings"
67)
78
89type Lesson struct {
@@ -146,13 +147,21 @@ type lessonSubmissionCLI struct {
146147 CLIResults []CLIStepResult
147148}
148149
149- type StructuredErrCLI struct {
150+ type verificationResult struct {
151+ ResultSlug string
152+ // user friendly message to put in the toast
153+ ResultMessage string
154+ // only present if the lesson is an CLI type
155+ StructuredErrCLI * VerificationResultStructuredErrCLI
156+ }
157+
158+ type VerificationResultStructuredErrCLI struct {
150159 ErrorMessage string `json:"Error"`
151160 FailedStepIndex int `json:"FailedStepIndex"`
152161 FailedTestIndex int `json:"FailedTestIndex"`
153162}
154163
155- func SubmitCLILesson (uuid string , results []CLIStepResult ) (* StructuredErrCLI , error ) {
164+ func SubmitCLILesson (uuid string , results []CLIStepResult ) (* VerificationResultStructuredErrCLI , error ) {
156165 bytes , err := json .Marshal (lessonSubmissionCLI {CLIResults : results })
157166 if err != nil {
158167 return nil , err
@@ -168,10 +177,24 @@ func SubmitCLILesson(uuid string, results []CLIStepResult) (*StructuredErrCLI, e
168177 if code != 200 {
169178 return nil , fmt .Errorf ("failed to submit CLI lesson (code: %v): %s" , code , string (resp ))
170179 }
171- var failure StructuredErrCLI
180+
181+ if strings .Contains (string (resp ), `"StructuredErrCLI"` ) {
182+ result := verificationResult {}
183+ err = json .Unmarshal (resp , & result )
184+ if err != nil {
185+ return nil , err
186+ }
187+ return result .StructuredErrCLI , nil
188+ }
189+ // TODO: delete this, it's for backwards compatibility
190+ // it used to be a top-object
191+ var failure VerificationResultStructuredErrCLI
172192 err = json .Unmarshal (resp , & failure )
173- if err != nil || failure .ErrorMessage == "" {
174- // this is ok - it means we had success
193+ if err != nil {
194+ return nil , err
195+ }
196+ if failure .ErrorMessage == "" {
197+ // no structured error, return nil, this is success
175198 return nil , nil
176199 }
177200 return & failure , nil
0 commit comments