From 818ca0b2e4117ca2cd4f4ab94ce84e6eebad5a71 Mon Sep 17 00:00:00 2001 From: Daniel Albers Date: Wed, 3 Jul 2024 13:45:33 +0200 Subject: [PATCH] Gracefully handle lookup errors in resolveDjangoUrl --- vue/src/utils/utils.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/vue/src/utils/utils.js b/vue/src/utils/utils.js index 6316d45fe5..b0ed1e9794 100644 --- a/vue/src/utils/utils.js +++ b/vue/src/utils/utils.js @@ -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]) } } } @@ -774,4 +779,4 @@ export const formFunctions = { } return form }, -} \ No newline at end of file +}