Compare commits

...

2 Commits

Author SHA1 Message Date
philipp lang 061b4a84c1 Fix proxy 2024-06-26 17:00:23 +02:00
philipp lang 88a57252ed Fix Exception handling errors 2024-06-26 14:47:49 +02:00
4 changed files with 14 additions and 11 deletions

View File

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

View File

@ -12,7 +12,7 @@ class ComponentException extends ApplicationException
public function __construct($message = "", $code = 0, Throwable $previous = null) 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); parent::__construct($translations['errors.' . $message] ?? $message, $code, $previous);
} }

View File

@ -7,7 +7,7 @@ class FetchSingleEvent
public function run(string $slug): ?array public function run(string $slug): ?array
{ {
$events = data_get(app(FetchAllEvents::class)->run(), 'data'); $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); return collect($events)->first(fn ($event) => $event['slug'] === $slug);
} }

View File

@ -20,13 +20,13 @@ class Proxy
protected function get(string $url): ?array protected function get(string $url): ?array
{ {
$response = Http::acceptJson()->get($this->url($url)); $response = Http::header('Accept', 'application/json')->get($this->url($url));
if (!$response->ok()) { if (!$response->ok) {
return null; return null;
} }
return $response->json(); return json_decode($response->body, true);
} }
public function submit(string $url): JsonResponse public function submit(string $url): JsonResponse
@ -36,9 +36,12 @@ class Proxy
'Authorization' => 'Bearer ' . request()->header('X-Adrema-Token'), 'Authorization' => 'Bearer ' . request()->header('X-Adrema-Token'),
] ]
: []; : [];
$response = Http::acceptJson()->withHeaders($headers)->post($this->url($url), request()->input()); $response = Http::make($this->url($url), 'POST')
->setOption(CURLOPT_POSTFIELDS, json_encode(request()->input()))
->header([...$headers, 'Accept' => 'application/json', 'Content-Type' => 'application/json'])
->send();
return response()->json($response->json(), $response->status()); return response()->json(json_decode($response->body, true), $response->code);
} }
private function url(string $internal): string private function url(string $internal): string