@@ -275,7 +275,6 @@ public function buildUrl($url, $query = [])
275
275
parse_str ($ url [1 ], $ query0 );
276
276
$ query = array_merge ($ query0 , $ query );
277
277
}
278
- $ query ['apikey ' ] = $ this ->key ;
279
278
280
279
$ url = $ url [0 ];
281
280
@@ -300,8 +299,8 @@ public function buildUrl($url, $query = [])
300
299
*/
301
300
public function request (RequestInterface $ request , $ attempt = 1 )
302
301
{
303
- if (! $ this ->key ) {
304
- throw new AlmaClientException ( ' No API key defined for ' . $ this ->zone );
302
+ if (isset ( $ this ->key ) ) {
303
+ $ request = $ request -> withHeader ( ' Authorization ' , ' apikey ' . $ this ->key );
305
304
}
306
305
foreach ($ this ->extraHeaders as $ key => $ val ) {
307
306
$ request = $ request ->withHeader ($ key , $ val );
@@ -593,6 +592,10 @@ protected function parseClientError(HttpException $exception)
593
592
// so we generalize it as a string.
594
593
$ code = empty ($ code ) ? null : (string ) $ code ;
595
594
595
+ if ($ code == 'UNAUTHORIZED ' ) {
596
+ return new InvalidApiKey ($ message , null , $ exception );
597
+ }
598
+
596
599
if (strtolower ($ message ) == 'invalid api key ' ) {
597
600
return new InvalidApiKey ($ message , null , $ exception );
598
601
}
0 commit comments