Skip to content

Commit 7bf7c64

Browse files
committed
fix: added catch for geographical test
1 parent ec8cfcf commit 7bf7c64

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

app/Rules/OnGeographicalBodyType.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Rules;
44

55
use Illuminate\Contracts\Validation\Rule;
6+
use Illuminate\Support\Facades\Log;
67

78
class OnGeographicalBodyType implements Rule
89
{
@@ -31,7 +32,16 @@ public function passes($attribute, $value)
3132
$lon = $value->longitude;
3233

3334
$api_url = 'https://api.onwater.io/api/v1/results/' . $lon . ',' . $lat;
34-
$json = json_decode(file_get_contents($api_url), true);
35+
36+
try {
37+
$json = json_decode(file_get_contents($api_url), true);
38+
} catch (\Exception $e) {
39+
// Log the error
40+
Log::error('Error while trying to get geographical body type: ' . $e->getMessage());
41+
42+
// If the API is down, we'll just let it pass
43+
return true;
44+
}
3545

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

0 commit comments

Comments
 (0)