Skip to content

Commit

Permalink
Ensure getInstallProperties always returns a value
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AlanGreene authored and tekton-robot committed Mar 25, 2024
1 parent a534dd3 commit 04450f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/api/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
});

Expand Down

0 comments on commit 04450f5

Please sign in to comment.