Skip to content

Commit

Permalink
chore: better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryan610 committed Jul 19, 2024
1 parent b354547 commit f38fd54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
14 changes: 10 additions & 4 deletions live/src/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ export const handleAuthentication = async (props: Props) => {
| TDocumentTypes
| undefined;
// fetch current user info
const response = await userService.currentUser(cookie);
let response;
try {
response = await userService.currentUser(cookie);
} catch (error) {
console.error("Failed to fetch current user:", error);
throw error;
}
if (response.id !== token) {
throw Error("Token doesn't match");
throw Error("Authentication failed: Token doesn't match the current user.");
}

if (documentType === "project_page") {
if (!workspaceSlug || !projectId) {
throw Error(
"Incomplete query params, workspaceSlug or projectId missing",
"Authentication failed: Incomplete query params. Either workspaceSlug or projectId is missing.",
);
}
// fetch current user's roles
Expand All @@ -43,7 +49,7 @@ export const handleAuthentication = async (props: Props) => {
connection.readOnly = true;
}
} else {
throw Error("Invalid document type provided");
throw Error("Authentication failed: Invalid document type provided.");
}

return {
Expand Down
6 changes: 6 additions & 0 deletions live/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export const updatePageDescription = async (
updatedDescription: Uint8Array,
cookie: string | undefined,
) => {
if (!(updatedDescription instanceof Uint8Array)) {
throw new Error(
"Invalid updatedDescription: must be an instance of Uint8Array",
);
}

const workspaceSlug = params.get("workspaceSlug")?.toString();
const projectId = params.get("projectId")?.toString();
if (!workspaceSlug || !projectId || !cookie) return;
Expand Down
2 changes: 1 addition & 1 deletion web/core/components/pages/editor/page-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const PageRoot = observer((props: TPageRootProps) => {
// states
const [editorReady, setEditorReady] = useState(false);
const [readOnlyEditorReady, setReadOnlyEditorReady] = useState(false);
const [sidePeekVisible, setSidePeekVisible] = useState(window.innerWidth >= 768 ? true : false);
const [sidePeekVisible, setSidePeekVisible] = useState(window.innerWidth >= 768);
// refs
const editorRef = useRef<EditorRefApi>(null);
const readOnlyEditorRef = useRef<EditorRefApi>(null);
Expand Down

0 comments on commit f38fd54

Please sign in to comment.