Skip to content

Commit 30f99e0

Browse files
authored
FCE-3321 throw missing sandbox url error when calling methods (#534)
## Description Moves the no sandbox url error to the moment user calls the backend. ## Documentation impact - [ ] Documentation update required - [ ] Documentation updated [in another PR](_) - [x] No documentation update required ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
1 parent 6d28d19 commit 30f99e0

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

packages/react-client/src/hooks/useSandbox.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useCallback } from "react";
22

3+
import { MissingSandboxApiUrlError } from "../utils/errors";
4+
35
type BasicInfo = { id: string; name: string };
46
type RoomManagerResponse = {
57
peerToken: string;
@@ -15,14 +17,12 @@ export type UseSandboxProps = {
1517
export type RoomType = "conference" | "livestream" | "audio_only";
1618

1719
export const useSandbox = (props: UseSandboxProps) => {
18-
const sandboxApiUrl = props?.sandboxApiUrl;
19-
20-
if (!sandboxApiUrl) {
21-
throw new Error("useSandbox requires a sandboxApiUrl, you can get it at: https://fishjam.io/app/sandbox");
22-
}
20+
const sandboxApiUrl = props.sandboxApiUrl;
2321

2422
const getSandboxPeerToken = useCallback(
2523
async (roomName: string, peerName: string, roomType: RoomType = "conference") => {
24+
if (!sandboxApiUrl) throw new MissingSandboxApiUrlError();
25+
2626
const url = new URL(sandboxApiUrl);
2727
url.searchParams.set("roomName", roomName);
2828
url.searchParams.set("peerName", peerName);
@@ -43,6 +43,8 @@ export const useSandbox = (props: UseSandboxProps) => {
4343

4444
const getSandboxViewerToken = useCallback(
4545
async (roomName: string) => {
46+
if (!sandboxApiUrl) throw new MissingSandboxApiUrlError();
47+
4648
const url = new URL(`${sandboxApiUrl}/${roomName}/livestream-viewer-token`);
4749

4850
const res = await fetch(url);
@@ -62,6 +64,8 @@ export const useSandbox = (props: UseSandboxProps) => {
6264

6365
const getSandboxLivestream = useCallback(
6466
async (roomName: string, isPublic: boolean = false) => {
67+
if (!sandboxApiUrl) throw new MissingSandboxApiUrlError();
68+
6569
const url = new URL(`${sandboxApiUrl}/livestream`);
6670
url.searchParams.set("roomName", roomName);
6771
url.searchParams.set("public", isPublic.toString());

packages/react-client/src/utils/errors.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ export const parseUserMediaError = (error: unknown, logger: ReturnType<typeof ge
2323
return UNHANDLED_ERROR;
2424
}
2525
};
26+
27+
export class MissingSandboxApiUrlError extends Error {
28+
constructor() {
29+
super("useSandbox requires a sandboxApiUrl, you can get it at: https://fishjam.io/app/sandbox");
30+
this.name = "MissingSandboxApiUrlError";
31+
}
32+
}

0 commit comments

Comments
 (0)