Giter Site home page Giter Site logo

Comments (7)

kirill-ratkin avatar kirill-ratkin commented on June 20, 2024

How I see function: wrap_function_by_validator(self, function, validator) intercepts ValidationError exception itself and print message.
So ... there is no way to detect validation error on application level, right?

from panini.

kirill-ratkin avatar kirill-ratkin commented on June 20, 2024

I just did minimal changes in pull request - #225 .
It's very simple soluton. Maybe it doesn't work for all cases. But it solves my problem with validation quite complicated messages come thru NATS and maybe helps you.

from panini.

artas728 avatar artas728 commented on June 20, 2024

Hello @kirill-ratkin
Indeed, catching a validator exception looks like a useful feature.
I'll check your PR soon

from panini.

artas728 avatar artas728 commented on June 20, 2024

@kirill-ratkin just checked PR #225
The thing is such implementation breaks all listener functions that don’t have an argument validation_report.
I would consider adding validation_error_cb as an argument for the listener decorator. For example:

async def custom_validation_error_cb(msg):
    # custom msg handling
    log.error(f"something wrong")

@app.listen("some.subject", validator=SomeValidator, validation_error_cb=custom_validation_error_cb)
async def foo(msg):
    # msg handling if everything allright
    log.info(f"got message {msg.data}")

What do you think? Would it be convenient for your case?

from panini.

kirill-ratkin avatar kirill-ratkin commented on June 20, 2024

Hi.
Yes. Good idea to add decorator parameter. It's better than mine solution.
What do you think to do with wrapped function call in case of validation error happened?

For my perpective wrapped functoin should not be called in this case and custom_validation_error_cb should be responsible for error handling. In my case I'll inform sender in reply about validation error.

Good idea!

from panini.

artas728 avatar artas728 commented on June 20, 2024

We will think about a wrapped function.

I can't guarantee but i think we will release the new version by the end of next week, the new version will include the validation error callback feature.

from panini.

artas728 avatar artas728 commented on June 20, 2024

#227 Update in new panini release - v0.7.1

from panini.

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.