From 59b86eb9dcb82fbacf67cccc2837d0530798995e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Fri, 27 Jun 2025 11:15:21 +0200 Subject: [PATCH] Correctly handle OpenAPI errors (#3401) --- .../DocumentView/OpenAPI/OpenAPIOperation.tsx | 10 ++++------ .../src/lib/openapi/resolveOpenAPIOperationBlock.ts | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPIOperation.tsx b/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPIOperation.tsx index 1fe281a75..539bbba2c 100644 --- a/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPIOperation.tsx +++ b/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPIOperation.tsx @@ -23,7 +23,7 @@ export async function OpenAPIOperation(props: BlockProps) { - const { block, context } = props; + const { block, context, style } = props; if (!context.contentContext) { return null; @@ -36,11 +36,9 @@ async function OpenAPIOperationBody(props: BlockProps if (error) { return ( -
-

- Error with {specUrl}: {error.message} -

-
+

+ Error while loading OpenAPI operation — {error.message} +

); } diff --git a/packages/gitbook/src/lib/openapi/resolveOpenAPIOperationBlock.ts b/packages/gitbook/src/lib/openapi/resolveOpenAPIOperationBlock.ts index fa980bd53..fb0ef3283 100644 --- a/packages/gitbook/src/lib/openapi/resolveOpenAPIOperationBlock.ts +++ b/packages/gitbook/src/lib/openapi/resolveOpenAPIOperationBlock.ts @@ -1,5 +1,5 @@ import { fetchOpenAPIFilesystem } from '@/lib/openapi/fetch'; -import { OpenAPIParseError } from '@gitbook/openapi-parser'; +import type { OpenAPIParseError } from '@gitbook/openapi-parser'; import { type OpenAPIOperationData, resolveOpenAPIOperation } from '@gitbook/react-openapi'; import type { AnyOpenAPIOperationsBlock, @@ -55,8 +55,8 @@ async function baseResolveOpenAPIOperationBlock( return { data, specUrl }; } catch (error) { - if (error instanceof OpenAPIParseError) { - return { error }; + if (error instanceof Error && error.name === 'OpenAPIParseError') { + return { error: error as OpenAPIParseError }; } throw error;