@@ -57,7 +57,10 @@ public function __construct(
5757 $ this ->appName = $ appName ;
5858 }
5959
60- public function generateSession (string $ token , string $ userId ): string {
60+ /**
61+ * @throws \Throwable when unable to generate or save a session
62+ */
63+ public function generateSession (string $ token , string $ userId ) : void {
6164 $ scrobbleService = $ this ->getApiService ();
6265 $ ch = $ this ->makeCurlHandle ($ scrobbleService );
6366 $ params = $ this ->generateBaseMethodParams ('auth.getSession ' );
@@ -69,7 +72,7 @@ public function generateSession(string $token, string $userId): string {
6972
7073 $ status = (string )$ xml ['status ' ];
7174 if ($ status !== 'ok ' ) {
72- return \sprintf ( ' Error %d: %s ' , ( int )$ xml ->error [ ' code ' ] , (string )$ xml ->error );
75+ throw new \ Exception (( string )$ xml ->error , (int )$ xml ->error [ ' code ' ] );
7376 }
7477
7578 try {
@@ -79,10 +82,9 @@ public function generateSession(string $token, string $userId): string {
7982 );
8083 $ this ->config ->setUserValue ($ userId , $ this ->appName , 'scrobbleSessionKey ' , $ encryptedKey );
8184 } catch (\Throwable $ e ) {
82- $ this ->logger ->error (" Unable to save session key " );
83- return $ e-> getMessage () ;
85+ $ this ->logger ->error (' Unable to save session key ' . $ e -> getMessage () );
86+ throw $ e ;
8487 }
85- return 'ok ' ;
8688 }
8789
8890 public function getApiKey () : ?string {
@@ -211,13 +213,14 @@ private function generateBaseMethodParams(string $method) : array {
211213 }
212214
213215 /**
214- * @return false|resource in PHP8+ false|\CurlHandle
216+ * @return resource in PHP8+ \CurlHandle
217+ * @throws \RuntimeException when unable to initialize a cURL handle
215218 */
216219 private function makeCurlHandle (string $ scrobblerServiceIdentifier ) {
217220 $ endpoint = self ::SCROBBLE_SERVICES [$ scrobblerServiceIdentifier ]['endpoint ' ];
218221 $ ch = \curl_init ($ endpoint );
219222 if (!$ ch ) {
220- return false ;
223+ throw new \ RuntimeException ( ' Unable to initialize a cURL handle ' ) ;
221224 }
222225 \curl_setopt ($ ch , \CURLOPT_CONNECTTIMEOUT , 10 );
223226 \curl_setopt ($ ch , \CURLOPT_POST , true );
0 commit comments