cloud_bbb/lib/Controller/Errors.php

29 lines
682 B
PHP
Raw Normal View History

2020-04-26 11:36:41 +02:00
<?php
namespace OCA\BigBlueButton\Controller;
use Closure;
use Exception;
2020-04-26 11:36:41 +02:00
use OCA\BigBlueButton\Service\RoomNotFound;
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;
trait Errors {
protected function handleNotFound(Closure $callback): DataResponse {
2020-04-26 11:36:41 +02:00
try {
$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
}
}
}