GithubHelp home page GithubHelp logo

Proposal for a new hook about raisin HOT 4 OPEN

khrt avatar khrt commented on September 5, 2024
Proposal for a new hook

from raisin.

Comments (4)

lmasarati avatar lmasarati commented on September 5, 2024

I propose this pull for the base feature of having a hook specific for failed data validation flow #76

from raisin.

khrt avatar khrt commented on September 5, 2024

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:

  1. Do not require a Raisin code change (not tested though should be working) is to add a middleware which would check error code and error message and add headers requested. It requires some kind of heuristics but should be okay in this case.
  2. Extend Raisin's code with adding an additional data structure which will hold information about which hook failed so you can do better detection in 1.

from raisin.

lmasarati avatar lmasarati commented on September 5, 2024

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.

from raisin.

lmasarati avatar lmasarati commented on September 5, 2024

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?

from raisin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.