Hi,
How should I translate exception messages?
Example:
<code>
try
{
$user = \Auth::create_user(
\Input::post('username'),
\Input::post('password'),
\Input::post('email'),
\Input::post('group')
);
}
catch (Exception $e)
{
// set translated $e->getMessage()
}
</code>
The problem is that \Auth::create_user always throws the same exception object SimpleUserUpdateException only with the different message:
<code>
throw new \SimpleUserUpdateException('Email address already exists');
throw new \SimpleUserUpdateException('Username already exists');
</code>
So it looks like the only way to decide what was the error is by checking message:
<code>
if($e->getMessage == 'Email address already exists')
\Session::set_flash('error', __('auth.exception.email_exists'));
elseif($e->getMessage == 'Username already exists')
\Session::set_flash('error', __('auth.exception.username_exists'));
</code>
But that just doesn't look right.
Any suggestions how should I do it the right way?
You have a point, this is not handy, these should be separate exceptions.
Can you create an issue at http://github.com/fuel/auth/issues so it can be picked up?