Files
gitbook/packages/openapi-parser/src/error.ts
conico974 a3855257c8 Gracefully handle OpenAPI fetch errors (#3455)
Co-authored-by: Nicolas Dorseuil <nicolas@gitbook.io>
2025-07-08 17:35:23 +02:00

33 lines
886 B
TypeScript

import type { ErrorObject } from '@scalar/openapi-parser';
export type OpenAPIParseErrorCode =
| 'invalid'
| 'parse-v2-in-v3'
| 'v2-conversion'
| 'dereference'
| 'yaml-parse';
/**
* Error thrown when the OpenAPI document is invalid.
*/
export class OpenAPIParseError extends Error {
public override name = 'OpenAPIParseError';
public code: OpenAPIParseErrorCode;
public rootURL: string | null;
public errors: ErrorObject[] | undefined;
constructor(
message: string,
options: {
code: OpenAPIParseErrorCode;
rootURL?: string | null;
cause?: Error;
errors?: ErrorObject[] | undefined;
}
) {
super(message, { cause: options.cause });
this.code = options.code;
this.rootURL = options.rootURL ?? null;
this.errors = options.errors;
}
}