Skip to content

Commit

Permalink
fix api null response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ell1ott committed Feb 23, 2024
1 parent 419e8eb commit d3829c6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lib/api/apiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ export interface Assignment {
export async function updateFiles() {
const api = getContext('api') as ApiHandler;

const userDocuments = await api.getUserDocuments();
const userDocumentsJson = await userDocuments.json();
const response = await api.getUserDocuments();
if (!response) {
throw new Error('Could not update files due to no response');
}
const userDocumentsJson = await response.json();
console.log(userDocumentsJson);

fileStore.set(userDocumentsJson);
Expand All @@ -57,18 +60,20 @@ export function updateUserInfo(state: AuthorizerState) {

// Explicitly specify the type of the store
export const fileStore = writable<FileInfo[]>([]);
export const assignmentStore = writable<Assignment[]>([]);

interface userInfo {
name: string;
}
export const userInfo = writable<userInfo>();

export const assignmentStore = writable<Assignment[]>([]);

export async function updateAssignments() {
const api = getContext('api') as ApiHandler;

const response = await api.getAssignments();
if (!response) {
throw new Error('Could not update assignments due to no response');
}
const json = await response.json();

assignmentStore.set(json);
Expand Down

0 comments on commit d3829c6

Please sign in to comment.