Handle the 404-exception thrown by guzzle
This commit is contained in:
parent
b10e918761
commit
811f401f30
1 changed files with 7 additions and 4 deletions
|
@ -84,13 +84,16 @@ $app->post('/', function (Request $request) use ($app, $config) {
|
||||||
$client = new Client($config['prosody']['http_base']);
|
$client = new Client($config['prosody']['http_base']);
|
||||||
|
|
||||||
$request = $client
|
$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']);
|
->setAuth($config['prosody']['user'], $config['prosody']['password']);
|
||||||
|
|
||||||
|
try {
|
||||||
$response = $request->send();
|
$response = $request->send();
|
||||||
|
|
||||||
if ($response->getStatusCode() != 404) {
|
|
||||||
$errors[] = $app->trans('Der Benutzername ist bereits vergeben.');
|
$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.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue