mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
26 lines
631 B
PHP
26 lines
631 B
PHP
<?php
|
|
|
|
namespace App\Services\Plugin\Parsers;
|
|
|
|
use Exception;
|
|
use Illuminate\Http\Client\Response;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class JsonOrTextResponseParser implements ResponseParser
|
|
{
|
|
public function parse(Response $response): array
|
|
{
|
|
try {
|
|
$json = $response->json();
|
|
if ($json !== null) {
|
|
return $json;
|
|
}
|
|
|
|
return ['data' => $response->body()];
|
|
} catch (Exception $e) {
|
|
Log::warning('Failed to parse JSON response: '.$e->getMessage());
|
|
|
|
return ['error' => 'Failed to parse JSON response'];
|
|
}
|
|
}
|
|
}
|