From 426f7ff16fe6726f98e318afd94acdb2aada70c5 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Fri, 17 Nov 2023 15:55:08 +1100 Subject: [PATCH] refactor getavailableclasses function --- src/SEQTA.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/SEQTA.js b/src/SEQTA.js index 126a2aa4..8d4a9236 100644 --- a/src/SEQTA.js +++ b/src/SEQTA.js @@ -1698,18 +1698,23 @@ function GetUpcomingAssessments() { .then((response) => response.payload); } -function GetActiveClasses() { - let func = fetch(`${location.origin}/seqta/student/load/subjects?`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json; charset=utf-8', - }, - body: JSON.stringify({}), - }); +async function GetActiveClasses() { + try { + const response = await fetch(`${location.origin}/seqta/student/load/subjects?`, { + method: 'POST', + headers: { 'Content-Type': 'application/json; charset=utf-8' }, + body: JSON.stringify({}) + }); - return func - .then((result) => result.json()) - .then((response) => response.payload); + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + + const data = await response.json(); + return data.payload; + } catch (error) { + console.error('Oops! There was a problem fetching active classes:', error); + } } function comparedate(obj1, obj2) {