Skip to content

Commit 59b86eb

Browse files
authored
Correctly handle OpenAPI errors (#3401)
1 parent 52c9f6d commit 59b86eb

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPIOperation.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function OpenAPIOperation(props: BlockProps<AnyOpenAPIOperationsBlo
2323
}
2424

2525
async function OpenAPIOperationBody(props: BlockProps<AnyOpenAPIOperationsBlock>) {
26-
const { block, context } = props;
26+
const { block, context, style } = props;
2727

2828
if (!context.contentContext) {
2929
return null;
@@ -36,11 +36,9 @@ async function OpenAPIOperationBody(props: BlockProps<AnyOpenAPIOperationsBlock>
3636

3737
if (error) {
3838
return (
39-
<div className="hidden">
40-
<p>
41-
Error with {specUrl}: {error.message}
42-
</p>
43-
</div>
39+
<p aria-hidden className={tcls(style)}>
40+
Error while loading OpenAPI operation — {error.message}
41+
</p>
4442
);
4543
}
4644

packages/gitbook/src/lib/openapi/resolveOpenAPIOperationBlock.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fetchOpenAPIFilesystem } from '@/lib/openapi/fetch';
2-
import { OpenAPIParseError } from '@gitbook/openapi-parser';
2+
import type { OpenAPIParseError } from '@gitbook/openapi-parser';
33
import { type OpenAPIOperationData, resolveOpenAPIOperation } from '@gitbook/react-openapi';
44
import type {
55
AnyOpenAPIOperationsBlock,
@@ -55,8 +55,8 @@ async function baseResolveOpenAPIOperationBlock(
5555

5656
return { data, specUrl };
5757
} catch (error) {
58-
if (error instanceof OpenAPIParseError) {
59-
return { error };
58+
if (error instanceof Error && error.name === 'OpenAPIParseError') {
59+
return { error: error as OpenAPIParseError };
6060
}
6161

6262
throw error;

0 commit comments

Comments
 (0)