Skip to content

Commit

Permalink
fix: added catch for geographical test
Browse files Browse the repository at this point in the history
  • Loading branch information
mwargan committed Apr 9, 2024
1 parent ec8cfcf commit 7bf7c64
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/Rules/OnGeographicalBodyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Log;

class OnGeographicalBodyType implements Rule
{
Expand Down Expand Up @@ -31,7 +32,16 @@ public function passes($attribute, $value)
$lon = $value->longitude;

$api_url = 'https://api.onwater.io/api/v1/results/' . $lon . ',' . $lat;
$json = json_decode(file_get_contents($api_url), true);

try {
$json = json_decode(file_get_contents($api_url), true);
} catch (\Exception $e) {
// Log the error
Log::error('Error while trying to get geographical body type: ' . $e->getMessage());

// If the API is down, we'll just let it pass
return true;
}

// If the API is down, we'll just let it pass
if (!isset($json['water'])) {
Expand Down

0 comments on commit 7bf7c64

Please sign in to comment.