Files
nextcloud-tables/lib/Controller/Errors.php
Florian Steffens 1641ea85a0 cleanup backend code & start with permissionService
tablesService is done

Signed-off-by: Florian Steffens <flost-dev@mailbox.org>
2022-03-07 21:54:19 +01:00

28 lines
892 B
PHP

<?php
namespace OCA\Tables\Controller;
use Closure;
use OCA\Tables\Errors\InternalError;
use OCA\Tables\Errors\NotFoundError;
use OCA\Tables\Errors\PermissionError;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
trait Errors {
protected function handleError(Closure $callback): DataResponse {
try {
return new DataResponse($callback());
} catch (PermissionError $e) {
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_FORBIDDEN);
} catch (NotFoundError $e) {
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_NOT_FOUND);
} catch (InternalError|\Exception $e) {
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR);
}
}
}