File tree 2 files changed +12
-7
lines changed
2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -105,9 +105,8 @@ public function getAttribute($key)
105
105
106
106
// First we will check for the presence of a mutator for the set operation
107
107
// which simply lets the developers tweak the attribute as it is set.
108
- if (method_exists ($ this , 'get ' . Str::studly ($ key ) . 'Attribute ' )) {
109
- $ method = 'get ' . Str::studly ($ key ) . 'Attribute ' ;
110
-
108
+ $ method = 'get ' . Str::studly ($ key ) . 'Attribute ' ;
109
+ if (method_exists ($ this , $ method )) {
111
110
return $ this ->{$ method }($ value );
112
111
}
113
112
Original file line number Diff line number Diff line change @@ -56,23 +56,29 @@ public function boot()
56
56
}
57
57
}
58
58
59
- /** {@inheritDoc} */
59
+ /**
60
+ * {@inheritDoc}
61
+ * @throws \RuntimeException
62
+ */
60
63
public function locate ($ ip )
61
64
{
62
- // Get data from client
65
+ // Get data from the client
63
66
$ data = $ this ->client ->get ('json/ ' . $ ip );
64
67
65
68
// Verify server response
66
69
if ($ this ->client ->getErrors () !== null ) {
67
- throw new Exception ( ' Request failed ( ' . $ this ->client ->getErrors () . ' ) ' );
70
+ throw new \ RuntimeException ( " Unexpected ip-api.com response: { $ this ->client ->getErrors ()}" );
68
71
}
69
72
70
73
// Parse body content
71
74
$ json = json_decode ($ data [0 ]);
75
+ if (! is_object ($ json ) || ! property_exists ($ json , 'status ' )) {
76
+ throw new \RuntimeException ("Unexpected ip-api.com response: {$ json ->message }" );
77
+ }
72
78
73
79
// Verify response status
74
80
if ($ json ->status !== 'success ' ) {
75
- throw new Exception ( ' Request failed ( ' . $ json ->message . ' ) ' );
81
+ throw new \ RuntimeException ( " Failed ip-api.com response: { $ json ->message }" );
76
82
}
77
83
78
84
return $ this ->hydrate ([
You can’t perform that action at this time.
0 commit comments