diff options
| author | vin <git@vineetk.net> | 2024-01-16 14:56:55 -0500 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2024-01-16 14:56:55 -0500 |
| commit | 3cf356f63895686e34aa0560c71dcb1ff8c29397 (patch) | |
| tree | 22bd50e4c23bb9a5c72a4395861d0f996b6b89cb | |
| parent | 627120b31f22f2f286fc2552f4586f29e7e1762c (diff) | |
handle roles not supported canvas error
| -rw-r--r-- | aplus.go | 15 |
1 files changed, 14 insertions, 1 deletions
| @@ -16,6 +16,10 @@ import ( | |||
| 16 | func submit_code(course_code int, attendance_code string) bool { | 16 | func submit_code(course_code int, attendance_code string) bool { |
| 17 | cur_body := launch_aplus(course_code) | 17 | cur_body := launch_aplus(course_code) |
| 18 | if cur_body == "" { | 18 | if cur_body == "" { |
| 19 | fmt.Println("Unknown error") | ||
| 20 | return false | ||
| 21 | } else if cur_body == "Roles not supported" { | ||
| 22 | fmt.Println("Cannot access course", course_code, "(canvas error \"Roles not supported\")") | ||
| 19 | return false | 23 | return false |
| 20 | } | 24 | } |
| 21 | 25 | ||
| @@ -101,7 +105,12 @@ func launch_aplus(course_code int) string { | |||
| 101 | 105 | ||
| 102 | resp, _ = client.PostForm(base_aplus_link, form_values) | 106 | resp, _ = client.PostForm(base_aplus_link, form_values) |
| 103 | body, _ = io.ReadAll(resp.Body) | 107 | body, _ = io.ReadAll(resp.Body) |
| 104 | return string(body) | 108 | |
| 109 | if strings.Index(string(body), "Roles not supported") != -1 { | ||
| 110 | return "Roles not supported" | ||
| 111 | } else { | ||
| 112 | return string(body) | ||
| 113 | } | ||
| 105 | } | 114 | } |
| 106 | 115 | ||
| 107 | func get_aplus(token string, link string, client http.Client) string { | 116 | func get_aplus(token string, link string, client http.Client) string { |
| @@ -183,6 +192,10 @@ func submit_code_sans_course(attendance_code string) { | |||
| 183 | func timetable(course_code int) { | 192 | func timetable(course_code int) { |
| 184 | cur_body := launch_aplus(course_code) | 193 | cur_body := launch_aplus(course_code) |
| 185 | if cur_body == "" { | 194 | if cur_body == "" { |
| 195 | fmt.Println("Unknown error") | ||
| 196 | return | ||
| 197 | } else if cur_body == "Roles not supported" { | ||
| 198 | fmt.Println("Cannot access course", course_code, "(canvas error \"Roles not supported\")") | ||
| 186 | return | 199 | return |
| 187 | } | 200 | } |
| 188 | 201 | ||
