nextcloud-app-radio/lib/Controller/Errors.php

22 lines
447 B
PHP
Raw Normal View History

2020-10-19 18:41:09 +00:00
<?php
namespace OCA\Radio\Controller;
use Closure;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
2020-10-30 20:16:02 +00:00
use OCA\Radio\Service\StationNotFound;
2020-10-19 18:41:09 +00:00
trait Errors {
protected function handleNotFound(Closure $callback): DataResponse {
try {
return new DataResponse($callback());
2020-10-30 20:16:02 +00:00
} catch (StationNotFound $e) {
2020-10-19 18:41:09 +00:00
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_NOT_FOUND);
}
}
}