Gracefully handle config fetch failure in cookie banner SDK

When the banner config request fails, the SDK now silently returns
instead of throwing, so the rest of the page is unaffected.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-24 17:57:50 +04:00
parent 11f856740a
commit 4982cebb9c
2 changed files with 13 additions and 1 deletions

View File

@@ -107,12 +107,22 @@ export class CookieBannerClient {
this.integrations = createDefaultIntegrations();
}
get loaded(): boolean {
return this.bannerConfig !== null;
}
async load(): Promise<void> {
const configUrl = new URL(`${this.bannerId}/config`, this.baseUrl);
if (this.lang) {
configUrl.searchParams.set("lang", this.lang);
}
const config = await fetchJSON<BannerConfig>(configUrl);
let config: BannerConfig;
try {
config = await fetchJSON<BannerConfig>(configUrl);
} catch {
return;
}
this.bannerConfig = config;
for (const integration of this.integrations) {

View File

@@ -147,6 +147,8 @@ export class ProboCookieBannerRoot extends ProboElement implements ProboRootElem
// Element was disconnected while load() was in-flight.
if (!this._client) return;
if (!this._client.loaded) return;
this._config = this._client.config;
this._draft = this.buildDraft(this._config);