Fix Exception handling errors

This commit is contained in:
philipp lang 2024-06-26 14:47:49 +02:00
parent 1b071ef37e
commit 88a57252ed
3 changed files with 6 additions and 6 deletions

View File

@ -114,10 +114,10 @@ abstract class EventManager extends ComponentBase
private function getPageFromProperty(string $property): Page
{
throw_if(!$this->property('indexPage') || !$this->property('singlePage') || !$this->property('registerPage'), ComponentException::class, 'silva.adrema::lang.not_all_pages_set');
throw_if(!$this->property('indexPage') || !$this->property('singlePage') || !$this->property('registerPage'), ComponentException::class, 'not_all_pages_set');
$page = Page::find($this->property($property));
throw_if($page === null, ComponentException::class, 'silva.adrema::lang.page_not_found');
throw_if($page === null, ComponentException::class, 'page_not_found');
return $page;
}
@ -131,8 +131,8 @@ abstract class EventManager extends ComponentBase
$singlePage = $this->getPageFromProperty('singlePage');
$registerPage = $this->getPageFromProperty('registerPage');
throw_if(!str($singlePage->url)->contains(':slug'), ComponentException::class, 'silva.adrema::lang.slug_not_found');
throw_if(!str($registerPage->url)->contains(':slug'), ComponentException::class, 'silva.adrema::lang.slug_not_found');
throw_if(!str($singlePage->url)->contains(':slug'), ComponentException::class, 'slug_not_found');
throw_if(!str($registerPage->url)->contains(':slug'), ComponentException::class, 'slug_not_found');
return [
'indexUrl' => $indexPage->url,

View File

@ -12,7 +12,7 @@ class ComponentException extends ApplicationException
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
$translations = json_decode(file_get_contents(__DIR__ . '/../lang/en.json'), true);
$translations = include(__DIR__ . '/../lang/en/lang.php');
parent::__construct($translations['errors.' . $message] ?? $message, $code, $previous);
}

View File

@ -7,7 +7,7 @@ class FetchSingleEvent
public function run(string $slug): ?array
{
$events = data_get(app(FetchAllEvents::class)->run(), 'data');
throw_if(is_null($events), ComponentException::class, 'silva.adrema::lang.event_fetching_failed');
throw_if(is_null($events), ComponentException::class, 'event_fetching_failed');
return collect($events)->first(fn ($event) => $event['slug'] === $slug);
}