Handle the 404-exception thrown by guzzle

This commit is contained in:
Tim Schumacher 2013-10-16 11:13:54 +02:00
parent b10e918761
commit 811f401f30

View file

@ -84,13 +84,16 @@ $app->post('/', function (Request $request) use ($app, $config) {
$client = new Client($config['prosody']['http_base']);
$request = $client
->get($config['prosody']['url_prefix'] . 'user/' . $user)
->get($config['prosody']['url_prefix'] . 'user/' . $user, array('Host' => $host))
->setAuth($config['prosody']['user'], $config['prosody']['password']);
$response = $request->send();
if ($response->getStatusCode() != 404) {
try {
$response = $request->send();
$errors[] = $app->trans('Der Benutzername ist bereits vergeben.');
} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {
if ($e->getCode() != 404) {
$errors[] = $app->trans('Der Benutzername ist bereits vergeben.');
}
}
}