Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- this is from Antonio Ramirez
- * Error handler, when there is an error this will fire
- * @param CEvent $event
- */
- public function apiErrorHandler(CEvent $event)
- {
- $event->handled = true;
- $debug = Yii::app()->params['yii.debug'];
- $response = array();
- if ($event instanceof CExceptionEvent)
- {
- if ($event->exception instanceof EApiError)
- {
- $response['code'] = $event->exception->statusCode;
- $response['message'] = $event->exception->getMessage();
- } else
- {
- $response['code'] = isset($event->exception->statusCode)
- ? $event->exception->statusCode
- : $event->exception->getCode();
- $response['message'] = $event->exception->getMessage();
- if ($debug)
- $response['traceback'] = $event->exception->getTrace();
- }
- } else if ($event instanceof CErrorEvent)
- {
- $response['code'] = 500;
- $response['message'] = $event->message;
- if ($debug)
- $response['traceback'] = debug_backtrace();
- }
- if (!$response['code'])
- $response['code'] = 500;
- try
- {
- HHttp::sendHttpResponseCode($response['code']);
- } catch (exception $e)
- {
- $response['code'] = 500;
- HHttp::sendHttpResponseCode($response['code']);
- }
- $this->renderJson($response);
- Yii::app()->end();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement