Hi wisher, Matthew Weier O'Phinney has put together a great library called PhlyRestfully. It handles among other things, returning a standardised API-Problem response for exceptions.
Contact me directly if you need help implementing it. Regards, Michael Gooden -----Original Message----- From: whisher <[email protected]> Date: Fri, 15 Mar 2013 11:18:11 To: <[email protected]> Subject: [fw-general] zend 2 AbstractRestfulController how to manage Exception Hi, I'm wondering how to manage Exception in AbstractRestfulController I set up the http://hounddog.github.com/blog/getting-started-with-rest-and-zend-framework-2/ project and I've tried with public function create($data) { try{ $artist = $this->getRequest()->getPost('artist', null); $title = $this->getRequest()->getPost('title', null); $album = new Album(); $album->exchangeArray(array('artist'=>$artist,'title'=>$title)); $id = $this->getAlbumTable()->saveAlbum($album); return $this->get($id); } catch (Exception $e) { return new JsonModel(array( 'meta' =>array( 'code'=>500, 'error-num'=>$e->getCode(), 'error-msg'=>$e->getMessage(), ) )); } } and also with public function saveAlbum(Album $album) { try{ $this->tableGateway->insert($data); $id = $this->tableGateway->getLastInsertValue(); return $id; } catch (Exception $e) { return new JsonModel(array( 'meta' =>array( 'code'=>500, 'error-num'=>$e->getCode(), 'error-msg'=>$e->getMessage(), ) )); } } but I keeping on having the all Exception stack I mean with the whole layout. My goal is get a json like { "meta": { "error_type": "error type", "code": 400, "error_message": "error msg" } } What's the right way ? -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/zend-2-AbstractRestfulController-how-to-manage-Exception-tp4659479.html Sent from the Zend Framework mailing list archive at Nabble.com. -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected]
