Skip to content

Commit 3d52b39

Browse files
committed
fix: crash with empty servers with redoc-cli
1 parent 3ae62f1 commit 3d52b39

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/utils/helpers.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,27 @@ export function resolveUrl(url: string, to: string) {
163163
}
164164

165165
export function getBasePath(serverUrl: string): string {
166-
return parseURL(serverUrl).pathname;
166+
try {
167+
return parseURL(serverUrl).pathname;
168+
} catch (e) {
169+
// when using with redoc-cli serverUrl can be empty resulting in crash
170+
return serverUrl;
171+
}
167172
}
168173

169174
export function titleize(text: string) {
170175
return text.charAt(0).toUpperCase() + text.slice(1);
171176
}
172177

173178
export function removeQueryString(serverUrl: string): string {
174-
const url = parseURL(serverUrl);
175-
url.search = '';
176-
return url.toString();
179+
try {
180+
const url = parseURL(serverUrl);
181+
url.search = '';
182+
return url.toString();
183+
} catch (e) {
184+
// when using with redoc-cli serverUrl can be empty resulting in crash
185+
return serverUrl;
186+
}
177187
}
178188

179189
function parseURL(url: string) {

0 commit comments

Comments
 (0)