Skip to content

Commit

Permalink
Gracefully handle lookup errors in resolveDjangoUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
AlD committed Jul 3, 2024
1 parent 17d34c5 commit 818ca0b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions vue/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,22 @@ export const ResolveUrlMixin = {
}

export function resolveDjangoUrl(url, params = null) {
let fun = window.Urls[url];
if (typeof fun !== 'function') {
console.error(`window.Urls[${url}] is not a function: ${fun}`);
return
}
if (params == null) {
return window.Urls[url]()
return fun()
} else if (typeof params != "object") {
return window.Urls[url](params)
return fun(params)
} else if (typeof params == "object") {
if (params.length === 1) {
return window.Urls[url](params)
return fun(params)
} else if (params.length === 2) {
return window.Urls[url](params[0], params[1])
return fun(params[0], params[1])
} else if (params.length === 3) {
return window.Urls[url](params[0], params[1], params[2])
return fun(params[0], params[1], params[2])
}
}
}
Expand Down Expand Up @@ -774,4 +779,4 @@ export const formFunctions = {
}
return form
},
}
}

0 comments on commit 818ca0b

Please sign in to comment.