From 03adb505558555cd2449bea0ae83c0a89c82a399 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 1 Nov 2019 18:31:12 +0100 Subject: util.error: Add well-known field 'code' in error templates Intended to be for HTTP-ish numeric status codes --- spec/util_error_spec.lua | 2 ++ util/error.lua | 1 + 2 files changed, 3 insertions(+) diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index d8534c2b..ca053285 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -16,11 +16,13 @@ describe("util.error", function () ["fail"] = { type = "wait", condition = "internal-server-error", + code = 555; }; }; local err = errors.new("fail", { traceback = "in some file, somewhere" }, templates); assert.equal("wait", err.type); assert.equal("internal-server-error", err.condition); + assert.equal(555, err.code); assert.same({ traceback = "in some file, somewhere" }, err.context); end); end); diff --git a/util/error.lua b/util/error.lua index 23551fe2..9ebfa6ab 100644 --- a/util/error.lua +++ b/util/error.lua @@ -14,6 +14,7 @@ local function new(e, context, registry) type = template.type or "cancel"; condition = template.condition or "undefined-condition"; text = template.text; + code = template.code or 500; context = context or template.context or { _error_id = e }; }, error_mt); -- cgit v1.2.3