Changeset

11352:e10567199f02

util.adhoc: Propagate error with producing initial initial data Bonus: Allow use of util.error tables
author Kim Alvefur <zash@zash.se>
date Sun, 31 Jan 2021 21:10:03 +0100
parents 11351:6b541d3c4c1b
children 11353:367e6beaf8ab
files util/adhoc.lua
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/util/adhoc.lua	Sun Jan 31 21:11:55 2021 +0100
+++ b/util/adhoc.lua	Sun Jan 31 21:10:03 2021 +0100
@@ -23,8 +23,14 @@
 			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