DEV Community

Discussion on: Domain Driven Design with PHP and Symfony

Collapse
 
juanma1331 profile image
juanma1331

Hi im new to backend development and im trying to implement the concepts explained in the article. But how can i catch exceptions thrown by the handlers on my controllers?. I can get returned data from handlers using envelopes, so i was thinking about returning data and error from handlers. What do you think about this? Any suggestion? Plz could you provide with some basic implementation? any repo? Thanks

Collapse
 
ludofleury profile image
Ludovic Fleury

Hi, welcome to backend dev ! I'll hope you will have a rich journey there :)

What you are mentioning is actually a pattern: notification.
Martin Fowler wrote about it there: martinfowler.com/articles/replaceT...

When dealing with a sync command (no rabbitmq etc) I favor intercepting exception directly in the controller, I don't have access to code right now, but something like this, should work:



class MyController
{
  public function xxx() 
  {
    try {
      $this->bus->dispatch($command);
    } catch ( exception )
      // rethrow with appropriate HTTP error code
   }
  }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
juanma1331 profile image
juanma1331

Thanks for your help. ;)