File tree Expand file tree Collapse file tree 2 files changed +9221
-3
lines changed
Expand file tree Collapse file tree 2 files changed +9221
-3
lines changed Original file line number Diff line number Diff line change 33 using System ;
44 using System . Collections . Generic ;
55 using System . Net . Http ;
6+ using System . Text . Json ;
67 using System . Threading . Tasks ;
78 using LearningHub . Nhs . Models . Entities . Reporting ;
89 using LearningHub . Nhs . Services . Interface ;
@@ -49,11 +50,23 @@ public async Task<List<MoodleCourseResponseViewModel>> GetEnrolledCoursesAsync(i
4950 if ( response . IsSuccessStatusCode )
5051 {
5152 var result = response . Content . ReadAsStringAsync ( ) . Result ;
52- viewmodel = JsonConvert . DeserializeObject < List < MoodleCourseResponseViewModel > > ( result ) ;
5353
54- foreach ( var course in viewmodel )
54+ using var document = JsonDocument . Parse ( result ) ;
55+ var root = document . RootElement ;
56+
57+ // Check if it's a JSON object and contains "exception"
58+ if ( ! ( root . ValueKind == JsonValueKind . Object && root . TryGetProperty ( "exception" , out _ ) ) )
59+ {
60+ viewmodel = JsonConvert . DeserializeObject < List < MoodleCourseResponseViewModel > > ( result ) ;
61+
62+ foreach ( var course in viewmodel )
63+ {
64+ course . CourseCompletionViewModel = await moodleApiService . GetCourseCompletionAsync ( userId , course . Id . Value , pageNumber ) ;
65+ }
66+ }
67+ else
5568 {
56- course . CourseCompletionViewModel = await moodleApiService . GetCourseCompletionAsync ( userId , course . Id . Value , pageNumber ) ;
69+ // Contains error, handle it as needed.
5770 }
5871 }
5972 else if ( response . StatusCode == System . Net . HttpStatusCode . Unauthorized ||
You can’t perform that action at this time.
0 commit comments