repod/lib/Controller/Errors.php
2023-06-23 09:44:48 +02:00

24 lines
467 B
PHP

<?php
declare(strict_types=1);
namespace OCA\RePod\Controller;
use Closure;
use OCA\RePod\Service\NoteNotFound;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
trait Errors {
protected function handleNotFound(Closure $callback): DataResponse {
try {
return new DataResponse($callback());
} catch (NoteNotFound $e) {
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_NOT_FOUND);
}
}
}