Open lmasarati opened 5 years ago
I propose this pull for the base feature of having a hook specific for failed data validation flow https://github.com/khrt/Raisin/pull/76
Hi @lmasarati, sorry it took that long to reply.
I've checked your PR and I have to reject it, because following this logic Raisin might end up having many-many other different hooks for a lot of other events.
I can think of two possible solutions at the moment, though both of a similar kind:
Thanks. Part 2 of the solution should be a good start. Developing a custom Middleware would not be a problem if Raisin publishes the result of validation in some environment variables.
about hooks in general, there's no way to force an immediate response from inside a hook.
For example a custom authorization or authentication could be placed inside the before hook, but in case of failure the request must pass through parameter and route validation before having a chance to be finalized.
What about using the hook return value to force a return $res->finalize
?
my $ret = eval {
$self->hook('before')->($self) and return $res->finalize;
The hook is then responsible for preparing the status, body, headers etc and returning 1 for forcing an immediate response to caller. What do you think?
I would find useful to add a new hook to be called in case of failed validation, to allow for modification of headers, content body before a standard 400 Bad Request response is returned. It is clear to me how to add such a hook, but not how to get validation errors that now are logged on STDERR.