From 5771047019242eca7d7c10f2bd95e5191de6f525 Mon Sep 17 00:00:00 2001 From: Alan Greene Date: Sat, 23 Mar 2024 20:42:27 +0000 Subject: [PATCH] Ensure getInstallProperties always returns a value With React Query 4+ a query function must always either return a value or throw an error. The install properties getter was previously returning undefined which meant React Query 3 would keep using the placeholder data. That's no longer the case so we have to return the default in this case. --- src/api/index.js | 11 +++++++++++ src/api/index.test.js | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/api/index.js b/src/api/index.js index 3275c8303..ca7add847 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -107,6 +107,10 @@ export async function getInstallProperties() { data = await get(uri); } catch (error) { if (error?.response?.status === 404) { + // eslint-disable-next-line no-console + console.warn( + 'Install properties not found, setting client-mode defaults' + ); data = { dashboardNamespace: 'N/A', dashboardVersion: 'kubectl-proxy-client', @@ -116,6 +120,13 @@ export async function getInstallProperties() { triggersNamespace: 'Unknown', triggersVersion: 'Unknown' }; + } else { + // eslint-disable-next-line no-console + console.error( + 'Failed loading install properties, setting read-only default', + error + ); + data = { isReadOnly: true }; } } return data; diff --git a/src/api/index.test.js b/src/api/index.test.js index ec6a87926..71bad725b 100644 --- a/src/api/index.test.js +++ b/src/api/index.test.js @@ -483,7 +483,7 @@ describe('getInstallProperties', () => { http.get(/\/properties$/, () => new HttpResponse(null, { status: 500 })) ); const properties = await API.getInstallProperties(); - expect(properties).toBeUndefined(); + expect(properties).toEqual({ isReadOnly: true }); }); });