teepluss / laravel-hmvc

HMVC is a tool for making internal request.
76 stars 20 forks source link

Exception handling / error response feature request #7

Open malhal opened 10 years ago

malhal commented 10 years ago

I'm invoking multiple requests and if any fail I'd like to receive the responses from the various App::error filters that I have configured for any of the many exceptions can be thrown. The default behaviour with this hmvc library is the whole app ends on the first exception. After some digging around, I've figured out the following work around:

foreach($requests as $request){
        try{
            $responses[] = HMVC::invoke($request['path'], $request['method'], array_key_exists('body',$request) ? $request['body'] : array());
        }catch(\Exception $e){
            $responses[] = json_decode(App::__get('exception')->handleException($e)->getContent());
        }

This way I either get the valid response or the error response for each request. I'd like to know if I've done this right, and if so, this would be a great feature to add to just make it return the error response in the normal invoke. Thanks!

phazei commented 9 years ago

Odd, I tried putting everything into a try catch but for whatever reason when it fails it doesn't bubble up to my catch and the whole app ends. I just use the generic exception. It happens specifically with request not found.

Edit: duh, I just caught "Exception" but I was namespaced, so it had to be "\Exception"