From 3d52b392745fa2151b524ee40903347c6261b92b Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 13 May 2019 15:49:54 +0300 Subject: [PATCH] fix: crash with empty servers with redoc-cli --- src/utils/helpers.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index cc909b6ac5..bfe8da946c 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -163,7 +163,12 @@ export function resolveUrl(url: string, to: string) { } export function getBasePath(serverUrl: string): string { - return parseURL(serverUrl).pathname; + try { + return parseURL(serverUrl).pathname; + } catch (e) { + // when using with redoc-cli serverUrl can be empty resulting in crash + return serverUrl; + } } export function titleize(text: string) { @@ -171,9 +176,14 @@ export function titleize(text: string) { } export function removeQueryString(serverUrl: string): string { - const url = parseURL(serverUrl); - url.search = ''; - return url.toString(); + try { + const url = parseURL(serverUrl); + url.search = ''; + return url.toString(); + } catch (e) { + // when using with redoc-cli serverUrl can be empty resulting in crash + return serverUrl; + } } function parseURL(url: string) {