# HG changeset patch # User Kim Alvefur # Date 1572629472 -3600 # Node ID 744ca71a49f72836faf670dc40cab67915fe9b43 # Parent 66943afdd7f3c6c7805c7a6d0399f785c2146943 util.error: Add well-known field 'code' in error templates Intended to be for HTTP-ish numeric status codes diff -r 66943afdd7f3 -r 744ca71a49f7 spec/util_error_spec.lua --- a/spec/util_error_spec.lua Fri Nov 01 18:11:58 2019 +0100 +++ b/spec/util_error_spec.lua Fri Nov 01 18:31:12 2019 +0100 @@ -16,11 +16,13 @@ ["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 -r 66943afdd7f3 -r 744ca71a49f7 util/error.lua --- a/util/error.lua Fri Nov 01 18:11:58 2019 +0100 +++ b/util/error.lua Fri Nov 01 18:31:12 2019 +0100 @@ -14,6 +14,7 @@ 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);