Skip to content

Commit 2da9428

Browse files
committed
fix(#181): Sentry error
1 parent 6818f2e commit 2da9428

File tree

2 files changed

+108
-29
lines changed

2 files changed

+108
-29
lines changed

web/components/SsrHeader.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ const SsrHeader: React.FC<SsrHeaderProps> = ({ user }) => {
4444
useState<boolean>(false);
4545

4646
const clearAllNotifications = async () => {
47-
await api.removeAllNotificationsForUser();
47+
try {
48+
await api.removeAllNotificationsForUser();
49+
} catch (e) {
50+
console.error(e);
51+
}
4852
refetch();
4953
};
5054

web/service/ApiService.ts

Lines changed: 103 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import {
1818
AssignmentWish,
1919
CodeComment,
2020
AssignmentWishesResponse,
21-
Notification, GroupJoinRequestPolicy, TaskyUser, GroupMembersResponse, AssignmentCompletionsResponse,
21+
Notification,
22+
GroupJoinRequestPolicy,
23+
TaskyUser,
24+
GroupMembersResponse,
25+
AssignmentCompletionsResponse,
2226
} from "@/service/types/tasky";
2327
import { FileStructureTree } from "@/components/FileStructure";
2428
import { Spotlight3Response } from "@/service/types/spotlight";
@@ -61,16 +65,34 @@ class ApiService {
6165
);
6266
}
6367

64-
public async createGroup(title: string, join_policy: GroupJoinRequestPolicy): Promise<Group> {
65-
return await this.post<Group>(`/tasky/create_group`, { title, join_policy });
68+
public async createGroup(
69+
title: string,
70+
join_policy: GroupJoinRequestPolicy,
71+
): Promise<Group> {
72+
return await this.post<Group>(`/tasky/create_group`, {
73+
title,
74+
join_policy,
75+
});
6676
}
6777

68-
public async updateGroup(groupId: number, title: string, join_policy: GroupJoinRequestPolicy): Promise<Group> {
69-
return await this.post<Group>(`/tasky/groups/${groupId}`, { title, join_policy });
78+
public async updateGroup(
79+
groupId: number,
80+
title: string,
81+
join_policy: GroupJoinRequestPolicy,
82+
): Promise<Group> {
83+
return await this.post<Group>(`/tasky/groups/${groupId}`, {
84+
title,
85+
join_policy,
86+
});
7087
}
7188

72-
public async getGroups(page?: number, search?: string): Promise<GroupsResponse> {
73-
return await this.get<GroupsResponse>(`/tasky/groups?page=${page ?? 1}&search=${search ?? ""}`);
89+
public async getGroups(
90+
page?: number,
91+
search?: string,
92+
): Promise<GroupsResponse> {
93+
return await this.get<GroupsResponse>(
94+
`/tasky/groups?page=${page ?? 1}&search=${search ?? ""}`,
95+
);
7496
}
7597

7698
public async getMyGroups(page?: number): Promise<GroupsResponse> {
@@ -117,7 +139,10 @@ class ApiService {
117139
);
118140
}
119141

120-
public async removeUserFromGroup(groupId: number, memberId: number): Promise<void> {
142+
public async removeUserFromGroup(
143+
groupId: number,
144+
memberId: number,
145+
): Promise<void> {
121146
await this.delete<any>(`/tasky/groups/${groupId}/members/${memberId}`);
122147
}
123148

@@ -294,7 +319,11 @@ class ApiService {
294319
}
295320

296321
public async getNotifications(): Promise<Notification[]> {
297-
return await this.get<Notification[]>(`/tasky/notifications`);
322+
try {
323+
return await this.get<Notification[]>(`/tasky/notifications`);
324+
} catch {
325+
return [];
326+
}
298327
}
299328

300329
public async removeNotificationForUser(id: number): Promise<void> {
@@ -305,8 +334,13 @@ class ApiService {
305334
await this.delete<any>("/tasky/notifications");
306335
}
307336

308-
public async searchUsersToEnlist(groupId: number, search: string): Promise<TaskyUser[]> {
309-
return await this.get<TaskyUser[]>(`/tasky/groups/${groupId}/enlistable?search=${search}`);
337+
public async searchUsersToEnlist(
338+
groupId: number,
339+
search: string,
340+
): Promise<TaskyUser[]> {
341+
return await this.get<TaskyUser[]>(
342+
`/tasky/groups/${groupId}/enlistable?search=${search}`,
343+
);
310344
}
311345

312346
public async enlistUser(groupId: number, userId: number): Promise<void> {
@@ -325,20 +359,35 @@ class ApiService {
325359
await this.delete<any>(`/tasky/groups/${groupId}`);
326360
}
327361

328-
public async getUserSolutions(id: number, page: number): Promise<SolutionsResponse> {
329-
return await this.get<SolutionsResponse>(`/tasky/user/${id}/solutions?page=${page}`);
362+
public async getUserSolutions(
363+
id: number,
364+
page: number,
365+
): Promise<SolutionsResponse> {
366+
return await this.get<SolutionsResponse>(
367+
`/tasky/user/${id}/solutions?page=${page}`,
368+
);
330369
}
331370

332371
public async getPendingSolutions(page: number): Promise<SolutionsResponse> {
333-
return await this.get<SolutionsResponse>(`/tasky/tutor_solutions?page=${page}`);
372+
return await this.get<SolutionsResponse>(
373+
`/tasky/tutor_solutions?page=${page}`,
374+
);
334375
}
335376

336-
public async getPendingWishes(page: number): Promise<AssignmentWishesResponse> {
337-
return await this.get<AssignmentWishesResponse>(`/tasky/tutor_assignment_wishes?page=${page}`);
377+
public async getPendingWishes(
378+
page: number,
379+
): Promise<AssignmentWishesResponse> {
380+
return await this.get<AssignmentWishesResponse>(
381+
`/tasky/tutor_assignment_wishes?page=${page}`,
382+
);
338383
}
339384

340-
public async getPendingAssignments(page: number): Promise<AssignmentsResponse> {
341-
return await this.get<AssignmentsResponse>(`/tasky/student_pending_assignments?page=${page}`);
385+
public async getPendingAssignments(
386+
page: number,
387+
): Promise<AssignmentsResponse> {
388+
return await this.get<AssignmentsResponse>(
389+
`/tasky/student_pending_assignments?page=${page}`,
390+
);
342391
}
343392

344393
public async verify(groupId: number): Promise<void> {
@@ -349,28 +398,54 @@ class ApiService {
349398
await this.post<any>(`/tasky/groups/${groupId}/unverify`, {});
350399
}
351400

352-
public async getGroupMembers(groupId: number, page: number): Promise<GroupMembersResponse> {
353-
return await this.get<GroupMembersResponse>(`/tasky/groups/${groupId}/members?page=${page}`);
401+
public async getGroupMembers(
402+
groupId: number,
403+
page: number,
404+
): Promise<GroupMembersResponse> {
405+
return await this.get<GroupMembersResponse>(
406+
`/tasky/groups/${groupId}/members?page=${page}`,
407+
);
354408
}
355409

356-
public async getAssignmentCompletions(groupId: number, assignmentId: number, page: number): Promise<AssignmentCompletionsResponse> {
357-
return await this.get<AssignmentCompletionsResponse>(`/tasky/groups/${groupId}/assignments/${assignmentId}/completions?page=${page}`);
410+
public async getAssignmentCompletions(
411+
groupId: number,
412+
assignmentId: number,
413+
page: number,
414+
): Promise<AssignmentCompletionsResponse> {
415+
return await this.get<AssignmentCompletionsResponse>(
416+
`/tasky/groups/${groupId}/assignments/${assignmentId}/completions?page=${page}`,
417+
);
358418
}
359419

360-
public async createGroupNotification(groupId: number, title: string, content: string): Promise<void> {
361-
await this.post<any>(`/tasky/groups/${groupId}/notifications`, {title, content})
420+
public async createGroupNotification(
421+
groupId: number,
422+
title: string,
423+
content: string,
424+
): Promise<void> {
425+
await this.post<any>(`/tasky/groups/${groupId}/notifications`, {
426+
title,
427+
content,
428+
});
362429
}
363430

364431
public async getSystemWideNotification(): Promise<Notification[]> {
365-
return await this.get<Notification[]>('/tasky/system_wide_notifications');
432+
return await this.get<Notification[]>("/tasky/system_wide_notifications");
366433
}
367434

368-
public async createSystemWideNotification(title: string, content: string, show_until: Date): Promise<void> {
369-
await this.post<any>('/tasky/system_wide_notifications', {title, content, show_until});
435+
public async createSystemWideNotification(
436+
title: string,
437+
content: string,
438+
show_until: Date,
439+
): Promise<void> {
440+
await this.post<any>("/tasky/system_wide_notifications", {
441+
title,
442+
content,
443+
show_until,
444+
});
370445
}
371446

372447
public async deleteSystemWideNotifications(id: number): Promise<void> {
373-
await this.delete<any>('/tasky/system_wide_notifications/'+id, {});
448+
await this.delete<any>("/tasky/system_wide_notifications/" + id, {});
374449
}
375450

376451
public async createOrUpdateCodeTests(

0 commit comments

Comments
 (0)