Currently Etna::Error raises with a simple message, as most errors do. However, often Etna applications produce complex, detailed error structures. These should be preserved on Etna::Error so they may be correctly formatted and passed on to the user.
To whit, we should amend Etna::Error#initialize to have an additional argument, payload=nil. Whatever object we like may be passed in here, available later via attr_reader :payload.
How might we make use of this? For example, in Etna::Controller when we rescue Etna::Error, this is the main error-formatting point for most Etna applications - with no JSON-payload error facility! Magma, notably, does not use Etna::Error hardly at all (it collects errors rather than raising), and instead uses Etna::Controller#failure directly to format its baroque JSON errors.
Etna::Controller should do the same, making use of Etna::Error#payload to determine whether there is any JSON content to the error (i.e., payload is not nil), which it can then use in place of e.message. This would allow Magma (etc.) to merely raise Etna::Error with a payload to return a JSON list of errors.
Currently Etna::Error raises with a simple message, as most errors do. However, often Etna applications produce complex, detailed error structures. These should be preserved on Etna::Error so they may be correctly formatted and passed on to the user.
To whit, we should amend
Etna::Error#initialize
to have an additional argument,payload=nil
. Whatever object we like may be passed in here, available later viaattr_reader :payload
.How might we make use of this? For example, in
Etna::Controller
when we rescueEtna::Error
, this is the main error-formatting point for most Etna applications - with no JSON-payload error facility! Magma, notably, does not useEtna::Error
hardly at all (it collects errors rather than raising), and instead usesEtna::Controller#failure
directly to format its baroque JSON errors.Etna::Controller should do the same, making use of Etna::Error#payload to determine whether there is any JSON content to the error (i.e., payload is not nil), which it can then use in place of
e.message
. This would allow Magma (etc.) to merely raise Etna::Error with a payload to return a JSON list of errors.