mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Correctly handle OpenAPI errors (#3401)
This commit is contained in:
@@ -23,7 +23,7 @@ export async function OpenAPIOperation(props: BlockProps<AnyOpenAPIOperationsBlo
|
||||
}
|
||||
|
||||
async function OpenAPIOperationBody(props: BlockProps<AnyOpenAPIOperationsBlock>) {
|
||||
const { block, context } = props;
|
||||
const { block, context, style } = props;
|
||||
|
||||
if (!context.contentContext) {
|
||||
return null;
|
||||
@@ -36,11 +36,9 @@ async function OpenAPIOperationBody(props: BlockProps<AnyOpenAPIOperationsBlock>
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="hidden">
|
||||
<p>
|
||||
Error with {specUrl}: {error.message}
|
||||
</p>
|
||||
</div>
|
||||
<p aria-hidden className={tcls(style)}>
|
||||
Error while loading OpenAPI operation — {error.message}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user