Now that we can handle exceptions, let's add some code to the get_by_username
function, so that we can take a deeper look at our problem.
1. Let's open
classes/user.php
, and add atry...catch
statement around our Sag call to make sure that we can handle any errors that occur.public static function get_by_username($username = null) { $bones = new Bones(); $bones->couch->login(ADMIN_USER, ADMIN_PASSWORD); $bones->couch->setDatabase('_users'); $user = new User(); try { $document = $bones->couch->get('org.couchdb.user:' . $username)->body; $user->_id = $document->_id; $user->name = $document->name; $user->email = $document->email; $user->full_name = $document->full_name; return $user; } catch (SagCouchException $e) { } }
2. Now that we are catching errors, let's add in our
error500
function.public static function get_by_username($username = null) { $bones = new Bones(); $bones->couch->login(ADMIN_USER...