fix(servers): prevent UI crash when chaning Server with variables
Closes #7525
This commit is contained in:
@@ -12,11 +12,11 @@ export function buildBaseUrl(selectedServer, specUrl) {
|
||||
if (!selectedServer) return specUrl
|
||||
if (isAbsoluteUrl(selectedServer)) return addProtocol(selectedServer)
|
||||
|
||||
return new URL(selectedServer, specUrl).href
|
||||
return new URL(selectedServer, specUrl).href
|
||||
}
|
||||
|
||||
export function buildUrl(url, specUrl, { selectedServer="" } = {}) {
|
||||
if (!url) return
|
||||
if (!url) return undefined
|
||||
if (isAbsoluteUrl(url)) return url
|
||||
|
||||
const baseUrl = buildBaseUrl(selectedServer, specUrl)
|
||||
@@ -25,3 +25,15 @@ export function buildUrl(url, specUrl, { selectedServer="" } = {}) {
|
||||
}
|
||||
return new URL(url, baseUrl).href
|
||||
}
|
||||
|
||||
/**
|
||||
* Safe version of buildUrl function. `selectedServer` can contain server variables
|
||||
* which can fail the URL resolution.
|
||||
*/
|
||||
export function safeBuildUrl(url, specUrl, { selectedServer="" } = {}) {
|
||||
try {
|
||||
return buildUrl(url, specUrl, { selectedServer })
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user