diff options
author | Kim Alvefur <zash@zash.se> | 2021-01-31 21:10:03 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-01-31 21:10:03 +0100 |
commit | 72cecbe03c0bfe2c91bafc3d83a4aa2891fc05c1 (patch) | |
tree | 573c3ba493dd59f2c6a6d15ad8e97d86087838e3 /util/adhoc.lua | |
parent | 8711e2bedce3958748e3a614e132834db56efe51 (diff) | |
download | prosody-72cecbe03c0bfe2c91bafc3d83a4aa2891fc05c1.tar.gz prosody-72cecbe03c0bfe2c91bafc3d83a4aa2891fc05c1.zip |
util.adhoc: Propagate error with producing initial initial data
Bonus: Allow use of util.error tables
Diffstat (limited to 'util/adhoc.lua')
-rw-r--r-- | util/adhoc.lua | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/util/adhoc.lua b/util/adhoc.lua index 19c94c34..a0ad52bb 100644 --- a/util/adhoc.lua +++ b/util/adhoc.lua @@ -23,8 +23,14 @@ local function new_initial_data_form(form, initial_data, result_handler) local fields, err = form:data(data.form); return result_handler(fields, err, data); else + local values, err = initial_data(data); + if type(err) == "table" then + return {status = "error"; error = err} + elseif type(err) == "string" then + return {status = "error"; error = {type = "cancel"; condition = "internal-server-error", err}} + end return { status = "executing", actions = {"next", "complete", default = "complete"}, - form = { layout = form, values = initial_data(data) } }, "executing"; + form = { layout = form, values = values } }, "executing"; end end end |