Giter VIP home page Giter VIP logo

Comments (3)

webdevilopers avatar webdevilopers commented on August 16, 2024

Normally we add value objects and asserts to our commands. So we thought about extending the try-catch-block to catch the exceptions:

But now we are thinking of moving the value objects to the "Handler":
#14

In that case we no longer would have to extend and keep it the original way - see initial comment.

from php-ddd.

webdevilopers avatar webdevilopers commented on August 16, 2024

We decided to make our Command DTOs (aka Symfony Form data classes) using primitives only again.
The creation of value objects was moved to the Command Handler.
Every value object throws a specific Domain Exception if they cannot be created or violate a business rule.

Now we can use a single try-catch block to catch the exceptions and transform them into a Symfony Form error.

This example features the @prooph service-bus. The actual Domain Exception can be accessed by getting the previous exception:

        $form->handleRequest($this->getRequest());

        if ($form->isValid()) {
            try {
                $this->get('prooph_service_bus.acme_command_bus')->dispatch($command);
            } catch (\Exception $busException) {
                switch (get_class($busException->getPrevious()))
                {
                    case InnerWidthIsOutOfRangeException::class:
                        $form->get('window')->addError(new FormError('...'));
                        break;
                }
            }
        }

Is there a better way to get and handle the domain exceptions @prolic @codeliner?

from php-ddd.

prolic avatar prolic commented on August 16, 2024

The service bus will throw its own exceptions. If you don't like this behavior and want it to throw your custom exceptions directly instead, attach a listener to finalize event on the bus and replace the exception with the previous one.

from php-ddd.

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.