Browse Source

Merge pull request #5896 from nextcloud/bugfix/noid/catch-correct-exception

Catch the correct exception in case of UniqueConstraintViolationExcep…
pull/5902/head
Vincent Petry 4 years ago
committed by GitHub
parent
commit
98a7296a22
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      lib/Controller/SignalingController.php
  2. 16
      lib/Service/SessionService.php

4
lib/Controller/SignalingController.php

@ -25,7 +25,6 @@ declare(strict_types=1);
namespace OCA\Talk\Controller;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCA\Talk\Config;
use OCA\Talk\Events\SignalingEvent;
use OCA\Talk\Exceptions\RoomNotFoundException;
@ -43,6 +42,7 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Http\Client\IClientService;
use OCP\IDBConnection;
@ -647,7 +647,7 @@ class SignalingController extends OCSController {
if ($sessionId && !$participant->getSession() instanceof Session) {
try {
$session = $this->sessionService->createSessionForAttendee($participant->getAttendee(), $sessionId);
} catch (UniqueConstraintViolationException $e) {
} catch (Exception $e) {
return new DataResponse([
'type' => 'error',
'error' => [

16
lib/Service/SessionService.php

@ -23,10 +23,10 @@ declare(strict_types=1);
namespace OCA\Talk\Service;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\Session;
use OCA\Talk\Model\SessionMapper;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Security\ISecureRandom;
@ -90,7 +90,7 @@ class SessionService {
* @param Attendee $attendee
* @param string $forceSessionId
* @return Session
* @throws UniqueConstraintViolationException
* @throws Exception
*/
public function createSessionForAttendee(Attendee $attendee, string $forceSessionId = ''): Session {
$session = new Session();
@ -98,12 +98,7 @@ class SessionService {
if ($forceSessionId !== '') {
$session->setSessionId($forceSessionId);
try {
$this->sessionMapper->insert($session);
} catch (UniqueConstraintViolationException $e) {
// The HPB told us to use a session which exists already…
throw $e;
}
$this->sessionMapper->insert($session);
} else {
while (true) {
$sessionId = $this->secureRandom->generate(255);
@ -111,8 +106,11 @@ class SessionService {
try {
$this->sessionMapper->insert($session);
break;
} catch (UniqueConstraintViolationException $e) {
} catch (Exception $e) {
// 255 chars are not unique? Try again...
if ($e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
throw $e;
}
}
}
}

Loading…
Cancel
Save