Skip to content

Commit dc3f60b

Browse files
authored
Use IntegrationError for known failures across built-in integrations (#1365)
1 parent 8f82c0d commit dc3f60b

76 files changed

Lines changed: 1219 additions & 178 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
'@gitbook/runtime': patch
3+
'@gitbook/integration-arcade': patch
4+
'@gitbook/integration-bucket': patch
5+
'@gitbook/integration-cognito': patch
6+
'@gitbook/integration-crisp': patch
7+
'@gitbook/integration-figma': patch
8+
'@gitbook/integration-formspree': patch
9+
'@gitbook/integration-freshdesk': patch
10+
'@gitbook/integration-front': patch
11+
'@gitbook/integration-github-copilot': patch
12+
'@gitbook/integration-github-files': patch
13+
'@gitbook/integration-gitlab-files': patch
14+
'@gitbook/integration-heap': patch
15+
'@gitbook/integration-hotjar': patch
16+
'@gitbook/integration-jira': patch
17+
'@gitbook/integration-launchdarkly': patch
18+
'@gitbook/integration-linear': patch
19+
'@gitbook/integration-lucid': patch
20+
'@gitbook/integration-mailchimp': patch
21+
'@gitbook/integration-mixpanel': patch
22+
'@gitbook/integration-oidc': patch
23+
'@gitbook/integration-pendo': patch
24+
'@gitbook/integration-posthog': patch
25+
'@gitbook/integration-reo.dev': patch
26+
'@gitbook/integration-runkit': patch
27+
'@gitbook/integration-segment': patch
28+
'@gitbook/integration-sentry': patch
29+
'@gitbook/integration-slack': patch
30+
'@gitbook/integration-va-auth0': patch
31+
'@gitbook/integration-va-azure': patch
32+
'@gitbook/integration-va-okta': patch
33+
'@gitbook/integration-webhook': patch
34+
'@gitbook/integration-zoominfo': patch
35+
---
36+
37+
Report recognized authentication, saved configuration and input failures with safe recovery guidance. Keep provider outages, rate limits and malformed responses unexpected, and preserve existing preview fallbacks and custom authentication responses.

‎integrations/arcade/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"typecheck": "tsc --noEmit",
1515
"check": "gitbook check",
1616
"publish-integrations": "gitbook publish .",
17-
"publish-integrations-staging": "gitbook publish ."
17+
"publish-integrations-staging": "gitbook publish .",
18+
"test": "bun test"
1819
}
1920
}

‎integrations/arcade/src/arcade.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ExposableError } from '@gitbook/runtime';
1+
import { IntegrationError } from '@gitbook/runtime';
22

33
export interface ArcadeOEmbed {
44
type: 'rich';
@@ -17,8 +17,11 @@ export async function fetchArcadeOEmbedData(flowId: string): Promise<ArcadeOEmbe
1717
const response = await fetch(url.toString());
1818

1919
if (!response.ok) {
20-
if (response.status < 500) {
21-
throw new ExposableError(response.statusText, response.status);
20+
if ([400, 404, 422].includes(response.status)) {
21+
throw new IntegrationError('invalid_input');
22+
}
23+
if (response.status === 401 || response.status === 403) {
24+
throw new IntegrationError('configuration_required');
2225
}
2326

2427
throw new Error(`${response.status} ${response.statusText}`);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { afterEach, describe, expect, it, mock } from 'bun:test';
2+
3+
import { ExposableError, IntegrationError } from '@gitbook/runtime';
4+
import { fetchArcadeOEmbedData } from '../src/arcade';
5+
6+
const ORIGINAL_FETCH = globalThis.fetch;
7+
8+
const request = () => fetchArcadeOEmbedData('flow');
9+
10+
afterEach(() => {
11+
globalThis.fetch = ORIGINAL_FETCH;
12+
});
13+
14+
describe('arcade provider failures', () => {
15+
it.each([
16+
[404, 'invalid_input'],
17+
[403, 'configuration_required'],
18+
] as const)('classifies HTTP %s as %s', async (status, reason) => {
19+
const fetchMock = mock(async () =>
20+
Response.json({ error: 'private-provider-body' }, { status }),
21+
);
22+
globalThis.fetch = fetchMock as unknown as typeof fetch;
23+
24+
const error = await request().catch((error) => error);
25+
expect(error).toBeInstanceOf(IntegrationError);
26+
expect(error).toMatchObject({ reason, code: reason === 'invalid_input' ? 422 : 424 });
27+
expect(error.message).not.toContain('private-provider-body');
28+
expect(fetchMock).toHaveBeenCalledTimes(1);
29+
});
30+
});
31+
32+
it.each([429, 503])('keeps HTTP %s unexpected', async (status) => {
33+
globalThis.fetch = mock(async () =>
34+
Response.json({ error: 'invalid_auth' }, { status }),
35+
) as unknown as typeof fetch;
36+
const error = await request().catch((error) => error);
37+
expect(error).toBeInstanceOf(Error);
38+
expect(error).not.toBeInstanceOf(ExposableError);
39+
});

‎integrations/arcade/tsconfig.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": "@gitbook/tsconfig/integration.json"
2+
"extends": "@gitbook/tsconfig/integration.json",
3+
"compilerOptions": {
4+
"types": ["@cloudflare/workers-types", "bun"]
5+
}
36
}

‎integrations/bucket/src/components.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createComponent, ExposableError } from '@gitbook/runtime';
1+
import { createComponent, IntegrationError } from '@gitbook/runtime';
22
import {
33
ReflagAction,
44
ReflagProps,
@@ -31,9 +31,7 @@ export const configBlock = createComponent<
3131

3232
const secretKey = element.state.secret_key;
3333
if (typeof secretKey !== 'string' || !secretKey) {
34-
throw new ExposableError(
35-
'Incomplete configuration: missing Reflag environment secret key',
36-
);
34+
throw new IntegrationError('invalid_input');
3735
}
3836

3937
const configurationBody: ReflagSiteInstallationConfiguration = {

‎integrations/bucket/src/schema.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Logger } from '@gitbook/runtime';
1+
import { IntegrationError, Logger } from '@gitbook/runtime';
22
import type { ReflagRuntimeContext } from './types';
33
import {
44
GitBookAPI,
@@ -47,7 +47,7 @@ export async function handleSyncAdaptiveSchema(
4747
? siteInstallation.configuration.secret_key
4848
: null;
4949
if (typeof secretKey !== 'string' || !secretKey) {
50-
throw new Error(`No secret key configured in the site installation ${siteId}`);
50+
throw new IntegrationError('configuration_required');
5151
}
5252

5353
const { data: site } = await api.orgs.getSiteById(organizationId, siteId);
@@ -161,6 +161,9 @@ async function getFeatureFlags(secretKey: string) {
161161
});
162162

163163
if (!res.ok) {
164+
if (res.status === 401 || res.status === 403) {
165+
throw new IntegrationError('configuration_required');
166+
}
164167
throw new Error(`(${res.status}) Failed to fetch feature flags: ${res.statusText}`);
165168
}
166169

‎integrations/cognito/src/index.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
RuntimeContext,
1313
RuntimeEnvironment,
1414
createComponent,
15-
ExposableError,
15+
IntegrationError,
1616
} from '@gitbook/runtime';
1717

1818
const logger = Logger('cognito.visitor-auth');
@@ -465,7 +465,7 @@ export default createIntegration({
465465
const clientId = configuration.client_id;
466466

467467
if (!clientId || !cognitoDomain) {
468-
throw new ExposableError('Cognito configuration is missing');
468+
throw new IntegrationError('configuration_required');
469469
}
470470

471471
const location = event.location ? event.location : '';

‎integrations/crisp/src/index.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
createIntegration,
3+
IntegrationError,
34
FetchPublishScriptEventCallback,
45
RuntimeContext,
56
RuntimeEnvironment,
@@ -22,11 +23,7 @@ export const handleFetchEvent: FetchPublishScriptEventCallback = async (
2223
) => {
2324
const trackingId = environment.siteInstallation?.configuration?.tracking_id;
2425
if (!trackingId) {
25-
throw new Error(
26-
`The Crisp Website ID is missing from the configuration (ID: ${
27-
'spaceId' in event ? event.spaceId : event.siteId
28-
}).`,
29-
);
26+
throw new IntegrationError('configuration_required');
3027
}
3128

3229
return new Response((script as string).replace('<TO_REPLACE>', trackingId), {

‎integrations/discord/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"private": true,
44
"scripts": {
55
"typecheck": "tsc --noEmit",
6-
"publish-integrations-staging": "gitbook publish ."
6+
"publish-integrations-staging": "gitbook publish .",
7+
"test": "bun test"
78
},
89
"devDependencies": {
910
"@gitbook/cli": "workspace:*",

0 commit comments

Comments
 (0)