, , Sentry2UserRepository , , IMO.
1: / , , ?
, , , . so that it will know what to display, , , . , , return $e->getMessage(), , . , , catch:
try{
}
catch( Exception $e )
{
if ($e instanceof UserNotFoundException) {
}
elseif ($e instanceof SomethinElseException) {
}
}
, catch, ..
class AnException extends Exception
{
public function customErrorMessage()
{
return `AnException occurred!`
}
}
class AnotherException extends Exception
{
public function customErrorMessage()
{
return `AnotherException occurred!`
}
}
catch, ..
try
{
}
catch(AnException $e)
{
return $e->customErrorMessage();
}
catch(AnotherException $e)
{
return $e->customErrorMessage();
}
catch(Exception $e)
{
return $e->getMessage();
}
2: json API /?
3: - JsonApi? WebUi. , Api?
, api, , . ,
class Sentry2UserRepository implements UserInterface {
public function findById($id) {
try {
return Sentry::findUserById($id);
}
catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) {
return false;
}
}
}
, , -
if(findById(5)) {
// found and dump it to the view
}
else {
// show "Not Found !", false will be back only for UserNotFoundException
}
UserNotFoundException catch
return $e; // or anything else (maybe an array containing status and message)
if(findById(5)) {
}
, $e oe , , somrthing,
$result = findById(5);
if($result && $result->code && $result->code === 0) {
}
, , -
if($result && $result->code) {
switch($result->code){
case 0:
break;
case 1:
break;
}
}
, IMO, , , , , . ? KISS. , .