File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Expand file tree Collapse file tree 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)
105105
106106 // First we will check for the presence of a mutator for the set operation
107107 // 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 )) {
111110 return $ this ->{$ method }($ value );
112111 }
113112
Original file line number Diff line number Diff line change @@ -56,23 +56,29 @@ public function boot()
5656 }
5757 }
5858
59- /** {@inheritDoc} */
59+ /**
60+ * {@inheritDoc}
61+ * @throws \RuntimeException
62+ */
6063 public function locate ($ ip )
6164 {
62- // Get data from client
65+ // Get data from the client
6366 $ data = $ this ->client ->get ('json/ ' . $ ip );
6467
6568 // Verify server response
6669 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 ()}" );
6871 }
6972
7073 // Parse body content
7174 $ 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+ }
7278
7379 // Verify response status
7480 if ($ json ->status !== 'success ' ) {
75- throw new Exception ( ' Request failed ( ' . $ json ->message . ' ) ' );
81+ throw new \ RuntimeException ( " Failed ip-api.com response: $ json ->message " );
7682 }
7783
7884 return $ this ->hydrate ([
You can’t perform that action at this time.
0 commit comments