Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow payload on Etna::Error #53

Open
graft opened this issue Jun 3, 2020 · 0 comments
Open

Allow payload on Etna::Error #53

graft opened this issue Jun 3, 2020 · 0 comments

Comments

@graft
Copy link
Contributor

graft commented Jun 3, 2020

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.

@graft graft changed the title Allow json payload on Etna::Error Allow payload on Etna::Error Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant