feat: handle error if api does not exist (#887)

This commit is contained in:
Yevhen Smoliy
2022-12-20 12:52:17 +02:00
committed by GitHub
parent b2700b541d
commit a1839e2976
18 changed files with 256 additions and 73 deletions

View File

@@ -1,5 +1,6 @@
import * as React from 'react';
import { createStore, Redoc } from 'redoc';
import { Config, isAbsoluteUrl } from '@redocly/openapi-core';
import { renderToString } from 'react-dom/server';
import { ServerStyleSheet } from 'styled-components';
@@ -8,7 +9,6 @@ import { join } from 'path';
import { existsSync, lstatSync, readFileSync } from 'fs';
import type { BuildDocsOptions } from './types';
import type { Config } from '@redocly/openapi-core';
import { red } from 'colorette';
import { exitWithError } from '../../utils';
@@ -62,7 +62,7 @@ export async function getPageHTML(
) {
process.stderr.write('Prerendering docs');
const apiUrl = redocOptions.specUrl || (isURL(pathToApi) ? pathToApi : undefined);
const apiUrl = redocOptions.specUrl || (isAbsoluteUrl(pathToApi) ? pathToApi : undefined);
const store = await createStore(api, apiUrl, redocOptions);
const sheet = new ServerStyleSheet();
@@ -93,10 +93,6 @@ export async function getPageHTML(
});
}
export function isURL(str: string): boolean {
return /^(https?:)\/\//m.test(str);
}
export function sanitizeJSONString(str: string): string {
return escapeClosingScriptTag(escapeUnicode(str));
}