mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-03-26 17:51:54 +01:00
prevent usage of combinedSettings if endpoints fail (which none of them should) (#2201)
This commit is contained in:
parent
020dff52f7
commit
e50b558b5b
@ -49,6 +49,21 @@ export default async function RootLayout({
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const combinedSettings = await fetchSettingsSS();
|
||||
if (!combinedSettings) {
|
||||
// Just display a simple full page error if fetching fails.
|
||||
return (
|
||||
<html lang="en">
|
||||
<Head>
|
||||
<title>Settings Unavailable</title>
|
||||
</Head>
|
||||
<body>
|
||||
<div className="error">
|
||||
Settings could not be loaded. Please try again later.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
|
@ -31,22 +31,49 @@ export async function fetchSettingsSS() {
|
||||
}
|
||||
}
|
||||
|
||||
const results = await Promise.all(tasks);
|
||||
try {
|
||||
const results = await Promise.all(tasks);
|
||||
|
||||
const settings = (await results[0].json()) as Settings;
|
||||
const enterpriseSettings =
|
||||
tasks.length > 1 ? ((await results[1].json()) as EnterpriseSettings) : null;
|
||||
const customAnalyticsScript = (
|
||||
tasks.length > 2 ? await results[2].json() : null
|
||||
) as string | null;
|
||||
const webVersion = getWebVersion();
|
||||
if (!results[0].ok) {
|
||||
throw new Error(
|
||||
`fetchStandardSettingsSS failed: status=${results[0].status} body=${await results[0].text()}`
|
||||
);
|
||||
}
|
||||
|
||||
const combinedSettings: CombinedSettings = {
|
||||
settings,
|
||||
enterpriseSettings,
|
||||
customAnalyticsScript,
|
||||
webVersion,
|
||||
};
|
||||
const settings = await results[0].json();
|
||||
|
||||
return combinedSettings;
|
||||
let enterpriseSettings = null;
|
||||
if (tasks.length > 1) {
|
||||
if (!results[1].ok) {
|
||||
throw new Error(
|
||||
`fetchEnterpriseSettingsSS failed: status=${results[1].status} body=${await results[1].text()}`
|
||||
);
|
||||
}
|
||||
enterpriseSettings = (await results[1].json()) as EnterpriseSettings;
|
||||
}
|
||||
|
||||
let customAnalyticsScript = null;
|
||||
if (tasks.length > 2) {
|
||||
if (!results[2].ok) {
|
||||
throw new Error(
|
||||
`fetchCustomAnalyticsScriptSS failed: status=${results[2].status} body=${await results[2].text()}`
|
||||
);
|
||||
}
|
||||
customAnalyticsScript = (await results[2].json()) as string;
|
||||
}
|
||||
|
||||
const webVersion = getWebVersion();
|
||||
|
||||
const combinedSettings: CombinedSettings = {
|
||||
settings,
|
||||
enterpriseSettings,
|
||||
customAnalyticsScript,
|
||||
webVersion,
|
||||
};
|
||||
|
||||
return combinedSettings;
|
||||
} catch (error) {
|
||||
console.error("fetchSettingsSS exception: ", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user