2020-04-26 11:36:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\BigBlueButton\Controller;
|
|
|
|
|
|
|
|
use Closure;
|
2020-06-15 17:23:53 +02:00
|
|
|
use Exception;
|
2020-04-26 11:36:41 +02:00
|
|
|
use OCA\BigBlueButton\Service\RoomNotFound;
|
2020-06-15 17:23:53 +02:00
|
|
|
use OCA\BigBlueButton\Service\RoomShareNotFound;
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
trait Errors {
|
|
|
|
protected function handleNotFound(Closure $callback): DataResponse {
|
2020-04-26 11:36:41 +02:00
|
|
|
try {
|
2020-06-15 17:23:53 +02:00
|
|
|
$return = $callback();
|
|
|
|
return ($return instanceof DataResponse) ? $return : new DataResponse($return);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
if ($e instanceof RoomNotFound ||
|
|
|
|
$e instanceof RoomShareNotFound) {
|
|
|
|
$message = ['message' => $e->getMessage()];
|
|
|
|
return new DataResponse($message, Http::STATUS_NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw $e;
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|