Skip to content

Commit

Permalink
Resolved an issue that could cause the component which presents chall…
Browse files Browse the repository at this point in the history
…enge questions to spam the API if a 500 is returned.
  • Loading branch information
sei-bstein committed Dec 6, 2023
1 parent 7c4a249 commit 5845873
Showing 1 changed file with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class GamespaceQuizComponent {
@Output() graded = new EventEmitter<boolean>();

pending = false;
errors: Error[] = [];
errors: any[] = [];
protected fa = fa;

constructor(
Expand All @@ -29,27 +29,24 @@ export class GamespaceQuizComponent {

async submit(): Promise<void> {
this.pending = true;
this.errors = [];

const submission = {
id: this.spec.instance!.id,
sectionIndex: this.spec.instance!.state.challenge?.sectionIndex,
questions: this.spec.instance!.state.challenge?.questions?.map(q => ({ answer: q.answer })),
};

await firstValueFrom(this.challengesService.grade(submission).pipe(
catchError((err, caughtChallenge) => {
this.errors.push(err);
return caughtChallenge;
}),
tap(c => {
if (c) {
this.spec.instance = c;
this.api.setColor(this.spec);
this.graded.emit(true);
}

this.pending = false;
})
));
try {
const gradedChallenge = await firstValueFrom(this.challengesService.grade(submission));
this.spec.instance = gradedChallenge;
this.api.setColor(this.spec);
this.graded.emit(true);
}
catch (err) {
this.errors.push(err);
}

this.pending = false;
}
}

0 comments on commit 5845873

Please sign in to comment.