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:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user