Skip to content

Commit

Permalink
refactor: update API calls to include throwOnError option
Browse files Browse the repository at this point in the history
  • Loading branch information
slashtechno committed Dec 27, 2024
1 parent c116e44 commit 880b4f2
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 222 deletions.
212 changes: 0 additions & 212 deletions frontend/pb_schema.json

This file was deleted.

5 changes: 4 additions & 1 deletion frontend/src/hooks.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ client.setConfig(
baseUrl: PUBLIC_API_URL,
headers: {
'Authorization': `Bearer ${user.token}`
}
},
// Instead of returning an error, throw an exception that can be caught with try/catch
// This can be overridden by passing throwOnError.
throwOnError: true
}
);
export const init: ServerInit = async () => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/user.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export function signOut() {
}

export function validateToken(token: string): Promise<void> {

return AuthService.protectedRouteProtectedRouteGet(
{
headers: {
Authorization: `Bearer ${token}`
}
},
throwOnError: true
}
).then((response) => {
if (!response.data) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/events/[id]/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const load: LayoutLoad = async ({ params, fetch }) => {
const event = await EventsService.getEventEventsEventIdGet({
path: {
event_id: params.id
}
},
throwOnError: true
});

if (!event.data) {
Expand All @@ -43,7 +44,6 @@ export const load: LayoutLoad = async ({ params, fetch }) => {
};
} catch (err) {
console.error(err);
console.debug("Client used to fetch event", client);
throw error(500, 'Failed to load event');
}
}
1 change: 0 additions & 1 deletion frontend/src/routes/events/[id]/leaderboard/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import ProjectCard from '$lib/components/ProjectCard.svelte';
import { onMount } from 'svelte';
import type { PageData } from './$types';
let eventId: string;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/events/[id]/leaderboard/+page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { api } from '$lib/api/client.svelte';
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';
import {client, EventsService} from '$lib/client/sdk.gen';
Expand All @@ -12,7 +11,8 @@ export const load: PageLoad = async ({ params, fetch }) => {
const projectsResp = await EventsService.getLeaderboardEventsEventIdLeaderboardGet({
path: {
event_id: id
}
},
throwOnError: true
});
return {
// If this isn't a list of projects, return an empty list
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/events/[id]/rank/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const load: PageLoad = async ({ params, fetch }) => {
const projects = await EventsService.getEventProjectsEventsEventIdProjectsGet({
path: {
event_id: id
}
},
throwOnError: true
});
if (!projects.data) {
throw error(404, 'No projects found');
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Even though error handling is done in the API, the try-finally block is used to ensure the loading state is reset
try {
const { data, error } = await UsersService.userExistsUsersExistsGet(
{ query: { email } },
{ query: { email }, throwOnError: false },
);
if (data?.exists) {
// Request magic link for the provided email if the user exists
Expand Down

0 comments on commit 880b4f2

Please sign in to comment.