1
0
Fork 0
nc_ext_dav_push/lib/Controller/Errors.php
2024-06-12 14:19:52 +02:00

25 lines
No EOL
581 B
PHP

<?php
namespace OCA\DavPush\Controller;
use Closure;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCA\DavPush\Errors\NotFoundException;
trait Errors {
protected function handleNotFound(Closure $callback): JSONResponse {
try {
return new JSONResponse($callback());
} catch (NotFoundException $e) {
return $this->notFoundResponse($e);
}
}
private function notFoundResponse(NotFoundException $e) {
$response = ['error' => get_class($e), 'message' => $e->getMessage()];
return new JSONResponse($response, Http::STATUS_NOT_FOUND);
}
}