@@ -191,6 +191,13 @@ type lessonSubmissionCLI struct {
191191 CLIResults []CLIStepResult
192192}
193193
194+ type SubmissionDebugData struct {
195+ Endpoint string
196+ RequestBody string
197+ ResponseStatusCode int
198+ ResponseBody string
199+ }
200+
194201type LessonSubmissionEvent struct {
195202 ResultSlug VerificationResultSlug
196203 StructuredErrCLI * StructuredErrCLI
@@ -212,27 +219,36 @@ const (
212219 VerificationResultSlugFailure VerificationResultSlug = "failure"
213220)
214221
215- func SubmitCLILesson (uuid string , results []CLIStepResult ) (LessonSubmissionEvent , error ) {
222+ func SubmitCLILesson (uuid string , results []CLIStepResult , captureDebug bool ) (LessonSubmissionEvent , SubmissionDebugData , error ) {
223+ endpoint := fmt .Sprintf ("/v1/lessons/%v/" , uuid )
224+ debugData := SubmissionDebugData {Endpoint : endpoint }
225+
216226 bytes , err := json .Marshal (lessonSubmissionCLI {CLIResults : results })
217227 if err != nil {
218- return LessonSubmissionEvent {}, err
228+ return LessonSubmissionEvent {}, debugData , err
219229 }
220- endpoint := fmt .Sprintf ("/v1/lessons/%v/" , uuid )
230+ if captureDebug {
231+ debugData .RequestBody = string (bytes )
232+ }
233+
221234 resp , code , err := fetchWithAuthAndPayload ("POST" , endpoint , bytes )
235+ debugData .ResponseStatusCode = code
236+ if captureDebug {
237+ debugData .ResponseBody = string (resp )
238+ }
222239 if err != nil {
223- return LessonSubmissionEvent {}, err
240+ return LessonSubmissionEvent {}, debugData , err
224241 }
225242 if code == 402 {
226- return LessonSubmissionEvent {}, fmt .Errorf ("to run and submit the tests for this lesson, you must have an active Boot.dev membership\n https://boot.dev/pricing" )
243+ return LessonSubmissionEvent {}, debugData , fmt .Errorf ("to run and submit the tests for this lesson, you must have an active Boot.dev membership\n https://boot.dev/pricing" )
227244 }
228245 if code != 200 {
229- return LessonSubmissionEvent {}, fmt .Errorf ("failed to submit CLI lesson (code %v): %s" , code , string (resp ))
246+ return LessonSubmissionEvent {}, debugData , fmt .Errorf ("failed to submit CLI lesson (code %v): %s" , code , string (resp ))
230247 }
231248
232249 result := LessonSubmissionEvent {}
233- err = json .Unmarshal (resp , & result )
234- if err != nil {
235- return LessonSubmissionEvent {}, err
250+ if err := json .Unmarshal (resp , & result ); err != nil {
251+ return LessonSubmissionEvent {}, debugData , err
236252 }
237- return result , nil
253+ return result , debugData , nil
238254}
0 commit comments