From 811f401f30c3de893839aacdd2c12119073734b1 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Wed, 16 Oct 2013 11:13:54 +0200 Subject: [PATCH] Handle the 404-exception thrown by guzzle --- index.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 7d84ed9..c437bdb 100644 --- a/index.php +++ b/index.php @@ -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.'); + } } }