@@ -26,13 +26,11 @@ use std::{
2626use tmc_langs:: {
2727 CommandError , Compression , Credentials , DownloadOrUpdateCourseExercisesResult , DownloadResult ,
2828 Language , StyleValidationResult , TmcConfig , UpdatedExercise ,
29- mooc:: MoocClient ,
30- tmc:: { TestMyCodeClient , TestMyCodeClientError , request:: FeedbackAnswer } ,
31- } ;
32- use tmc_langs_util:: {
33- deserialize,
3429 file_util:: { self , Lock , LockOptions } ,
30+ mooc:: { MoocClient , MoocClientError } ,
31+ tmc:: { TestMyCodeClient , TestMyCodeClientError , request:: FeedbackAnswer } ,
3532} ;
33+ use tmc_langs_util:: deserialize;
3634
3735pub enum ParsingResult {
3836 Ok ( Cli ) ,
@@ -104,7 +102,7 @@ fn solve_error_kind(e: &anyhow::Error) -> Kind {
104102 return Kind :: InvalidToken ;
105103 }
106104
107- // check for client errors
105+ // check for tmc client errors
108106 match cause. downcast_ref :: < TestMyCodeClientError > ( ) {
109107 Some ( TestMyCodeClientError :: HttpError {
110108 url : _,
@@ -131,6 +129,33 @@ fn solve_error_kind(e: &anyhow::Error) -> Kind {
131129 _ => { }
132130 }
133131
132+ // check for tmc client errors
133+ match cause. downcast_ref :: < MoocClientError > ( ) {
134+ Some ( MoocClientError :: HttpError {
135+ url : _,
136+ status,
137+ error : _,
138+ obsolete_client,
139+ } ) => {
140+ if * obsolete_client {
141+ return Kind :: ObsoleteClient ;
142+ }
143+ if status. as_u16 ( ) == 403 {
144+ return Kind :: Forbidden ;
145+ }
146+ if status. as_u16 ( ) == 401 {
147+ return Kind :: NotLoggedIn ;
148+ }
149+ }
150+ Some ( MoocClientError :: NotAuthenticated ) => {
151+ return Kind :: NotLoggedIn ;
152+ }
153+ Some ( MoocClientError :: ConnectionError { .. } ) => {
154+ return Kind :: ConnectionError ;
155+ }
156+ _ => { }
157+ }
158+
134159 // check for download failed error
135160 if let Some ( DownloadsFailedError {
136161 downloaded : completed,
@@ -308,16 +333,16 @@ fn run_app(cli: Cli) -> Result<CliOutput> {
308333 )
309334 }
310335
311- Command :: ListLocalCourseExercises {
336+ Command :: ListLocalTmcCourseExercises {
312337 client_name,
313338 course_slug,
314339 } => {
315340 let local_exercises =
316- tmc_langs:: list_local_course_exercises ( & client_name, & course_slug) ?;
341+ tmc_langs:: list_local_tmc_course_exercises ( & client_name, & course_slug) ?;
317342
318343 CliOutput :: finished_with_data (
319344 format ! ( "listed local exercises for {course_slug}" ) ,
320- DataKind :: LocalExercises ( local_exercises) ,
345+ DataKind :: LocalTmcExercises ( local_exercises) ,
321346 )
322347 }
323348
@@ -1008,7 +1033,9 @@ fn run_tmc_inner(
10081033
10091034fn run_mooc ( mooc : Mooc ) -> Result < CliOutput > {
10101035 let root_url = env:: var ( "TMC_LANGS_MOOC_ROOT_URL" )
1011- . unwrap_or_else ( |_| "https://courses.mooc.fi" . to_string ( ) ) ;
1036+ . unwrap_or_else ( |_| "https://courses.mooc.fi/" . to_string ( ) )
1037+ . parse ( )
1038+ . context ( "Invalid TMC root url" ) ?;
10121039
10131040 let ( mut client, credentials) =
10141041 tmc_langs:: init_mooc_client_with_credentials ( root_url, & mooc. client_name ) ?;
@@ -1038,6 +1065,11 @@ fn run_mooc(mooc: Mooc) -> Result<CliOutput> {
10381065
10391066fn run_mooc_inner ( mooc : Mooc , client : & mut MoocClient ) -> Result < CliOutput > {
10401067 let output = match mooc. command {
1068+ MoocCommand :: CourseInstance {
1069+ course_instance_id : _,
1070+ } => {
1071+ todo ! ( )
1072+ }
10411073 MoocCommand :: CourseInstances => {
10421074 let course_instances = client. course_instances ( ) ?;
10431075 CliOutput :: finished_with_data (
@@ -1046,8 +1078,7 @@ fn run_mooc_inner(mooc: Mooc, client: &mut MoocClient) -> Result<CliOutput> {
10461078 )
10471079 }
10481080 MoocCommand :: CourseInstanceExercises { course_instance_id } => {
1049- let course_instance_exercises =
1050- client. course_instance_exercise_slides ( course_instance_id) ?;
1081+ let course_instance_exercises = client. course_instance_exercises ( course_instance_id) ?;
10511082 CliOutput :: finished_with_data (
10521083 "fetched course instance exercises" ,
10531084 DataKind :: MoocExerciseSlides ( course_instance_exercises) ,
0 commit comments