liberator
liberator copied to clipboard
defaction should take a failure case
This is the reason why defaction take the same case for the different outcomes. The truth is that there should be a different case where the intended action did not succeed.
to be honest, I'm not so happy with the defactions at all. If a desired post side effect cannot proceed, then the decision processable?
should have signaled that. I see that sometimes the outcome of a backend operation is not know until tried, but nothing prevents the resource from doing the call earlier, remember a possible outcome in the context and use that in later decisions.
The other way to implement it, is to raise an exception and match on it in handle-exception
, however you'd need to derive a status code yourself.
Assuming that post!
would allow a falsy outcome what's the remaining decision flow? Can you suggest something?
Firstly, I'll like to see liberator decision graph workflow be extensible. Secondly, to answer your question, since delete!
has delete-enacted?
, post!
can also have something similar to indicate if it was succesful or not due to validation errors or some such.
But looking at the graph again, I do think processable?
is a good place to decide if the operation will go through. Another thing is that I think processable?
should come early enough to allow performing validation work there even before authorized?
and allowed?
decisions because data used to do those needs to be validated. What do you think?
There will never be a one-size-fits-all. Until liberator has custom workflows (which is a challenge on it's own) you will need to move some checks to earlier decisions as I described in my first comment. I.e. in authorized?
or even service-available?
process the resource, stop the outcome regarding validation and authorization in the context and look it up in the decision functions:
(defresource foo []
:service-available
(fn [{{{param1 :param1} :form-params} :request}]
(if-let [v (lookup-from-db param1])
{::processable? true
::authorized? (is-user-allowed? v)}
{::processable? false}))
:authorized? ::authorized?
:procesable? ::processable?)