From 5db9384c9ce95543fd70968fa89b8b2aaf29bcc6 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Thu, 8 Dec 2022 14:32:50 -0500 Subject: [PATCH] Fix currentApiClient return type to include undefined --- src/components/ConnectionRequired.tsx | 4 ++-- src/components/ServerConnections.js | 2 +- src/components/ServerContentPage.tsx | 2 +- src/hooks/useApi.tsx | 2 +- src/plugins/syncPlay/core/Manager.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/ConnectionRequired.tsx b/src/components/ConnectionRequired.tsx index 1bc211c43a..aa67a257e1 100644 --- a/src/components/ConnectionRequired.tsx +++ b/src/components/ConnectionRequired.tsx @@ -128,8 +128,8 @@ const ConnectionRequired: FunctionComponent = ({ // If this is an admin route, ensure the user has access if (isAdminRequired) { try { - const user = await client.getCurrentUser(); - if (!user.Policy?.IsAdministrator) { + const user = await client?.getCurrentUser(); + if (!user?.Policy?.IsAdministrator) { console.warn('[ConnectionRequired] normal user attempted to access admin route'); bounce(await ServerConnections.connect()); return; diff --git a/src/components/ServerConnections.js b/src/components/ServerConnections.js index 2ae12aad36..9bdb82fc60 100644 --- a/src/components/ServerConnections.js +++ b/src/components/ServerConnections.js @@ -88,7 +88,7 @@ class ServerConnections extends ConnectionManager { /** * Gets the ApiClient that is currently connected. - * @returns {ApiClient} apiClient + * @returns {ApiClient|undefined} apiClient */ currentApiClient() { let apiClient = this.getLocalApiClient(); diff --git a/src/components/ServerContentPage.tsx b/src/components/ServerContentPage.tsx index f5c705cf6f..7473c856e8 100644 --- a/src/components/ServerContentPage.tsx +++ b/src/components/ServerContentPage.tsx @@ -34,7 +34,7 @@ const ServerContentPage: FunctionComponent = ({ view }) const apiClient = ServerConnections.currentApiClient(); // Fetch the view html from the server and translate it - const viewHtml = await apiClient.get(apiClient.getUrl(view + location.search)) + const viewHtml = await apiClient?.get(apiClient.getUrl(view + location.search)) .then((html: string) => globalize.translateHtml(html)); viewManager.loadView({ diff --git a/src/hooks/useApi.tsx b/src/hooks/useApi.tsx index 409b40875f..7828db6cd8 100644 --- a/src/hooks/useApi.tsx +++ b/src/hooks/useApi.tsx @@ -23,7 +23,7 @@ export const ApiProvider: FC = ({ children }) => { useEffect(() => { ServerConnections.currentApiClient() - .getCurrentUser() + ?.getCurrentUser() .then(newUser => updateApiUser(undefined, newUser)) .catch(err => { console.info('[ApiProvider] Could not get current user', err); diff --git a/src/plugins/syncPlay/core/Manager.js b/src/plugins/syncPlay/core/Manager.js index af39d422d4..740e0709d9 100644 --- a/src/plugins/syncPlay/core/Manager.js +++ b/src/plugins/syncPlay/core/Manager.js @@ -71,7 +71,7 @@ class Manager { /** * Update active ApiClient. - * @param {Object} apiClient The ApiClient. + * @param {ApiClient|undefined} apiClient The ApiClient. */ updateApiClient(apiClient) { if (!apiClient) {