Mathew Attlee
Mathew Attlee

Reputation: 549

Equivalent of Zend_Controller_Plugin_ErrorHandler and Zend_Controller_Action_Exception in Zend framework 2

What's the equivalent of Zend_Controller_Plugin_ErrorHandler and Zend_Controller_Action_Exception in Zend framework 2? I am used to writing an ErrorController in past versions of the framework (eg http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html) but now am using version two and I can't find any examples of how you write a custom error handler.

In my instance I am writing a REST server and would like to throw exceptions that correspond to particular HTTP error codes.

From what I can tell, it appears I might need to write my own custom version of Zend\Mvc\View\Http\ExceptionStrategy which is invoked by Zend\Mvc\View\Http\ViewManager

Upvotes: 0

Views: 409

Answers (1)

kokx
kokx

Reputation: 1706

ZF2 does not have something that is really equivalent to the Error Handler with an ErrorController in ZF1. I don't recommend trying to implement something similiar in ZF2 (because it works very, very different).

In your case, I would simply use the default Zend\Mvc\View\Http\ExceptionStrategy, and then use the view script to differentiate between different error codes and types of requests.

Upvotes: 1

Related Questions