Skip to content

Commit

Permalink
fix: crash with empty servers with redoc-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed May 13, 2019
1 parent 3ae62f1 commit 3d52b39
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,27 @@ 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) {
return text.charAt(0).toUpperCase() + text.slice(1);
}

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) {
Expand Down

0 comments on commit 3d52b39

Please sign in to comment.