File tree Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,15 @@ class IPApi extends AbstractService
22
22
*/
23
23
protected $ continents ;
24
24
25
+
26
+ /**
27
+ * Values to try content.
28
+ *
29
+ * @var integer
30
+ */
31
+ protected $ tries = 3 ;
32
+
33
+
25
34
/**
26
35
* The "booting" method of the service.
27
36
*
@@ -70,8 +79,34 @@ public function locate($ip)
70
79
// Parse body content
71
80
$ json = json_decode ($ data [0 ]);
72
81
82
+
83
+ # Has data
84
+ if (!$ json ) {
85
+ $ this ->tries = $ this ->tries -1 ; #2(1) 1(2)
86
+ if ($ this ->tries < 0 ) {
87
+
88
+ # requests fails, give empty values back
89
+ return $ this ->hydrate ([
90
+ 'ip ' => $ ip ,
91
+ 'iso_code ' => null ,
92
+ 'country ' => null ,
93
+ 'city ' => null ,
94
+ 'state ' => null ,
95
+ 'state_name ' => null ,
96
+ 'postal_code ' => null ,
97
+ 'lat ' => null ,
98
+ 'lon ' => null ,
99
+ 'timezone ' => null ,
100
+ 'continent ' => $ this ->getContinent (null )
101
+ ]);
102
+ }
103
+
104
+ # try same request again
105
+ return $ this ->locate ($ ip );
106
+ }
107
+
73
108
// Verify response status
74
- if ($ json && $ json ->status !== 'success ' ) {
109
+ if ($ json ->status !== 'success ' ) {
75
110
throw new Exception ('Request failed ( ' . $ json ->message . ') ' );
76
111
}
77
112
You can’t perform that action at this time.
0 commit comments