Skip to content

Commit 42ee16e

Browse files
committed
refactor: improve exception handling in GetUsersList
1 parent 01365b7 commit 42ee16e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Backends/Plex/Action/GetUserToken.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private function getUserToken(Context $context, int|string $userId, string $user
8888
'url' => (string) $url,
8989
]);
9090

91-
$opts['user_info'] = ['username' => $username];
91+
$opts['user_info'] = ['username' => $username, 'user_id' => $userId];
9292

9393
$response = $this->request(Method::POST, $url, Status::CREATED, $context, array_replace_recursive([
9494
'headers' => ['Accept' => 'application/json'],
@@ -141,6 +141,10 @@ private function getUserToken(Context $context, int|string $userId, string $user
141141
],
142142
], $opts));
143143

144+
if (true === $response instanceof Response) {
145+
return $response;
146+
}
147+
144148
$json = json_decode(
145149
json: $response->getContent(),
146150
associative: true,

src/Backends/Plex/Action/GetUsersList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private function getHomeUsers(Response $users, Context $context, array $opts = [
152152
'Accept' => 'application/json',
153153
],
154154
]);
155-
} catch (InvalidArgumentException $e) {
155+
} catch (InvalidArgumentException|iException $e) {
156156
return new Response(
157157
status: false,
158158
error: new Error(
@@ -340,7 +340,7 @@ private function getExternalUsers(Context $context, array $opts = []): Response
340340
if (true !== (bool) ag($opts, Options::GET_TOKENS) || count($users) < 1) {
341341
return new Response(status: true, response: $users);
342342
}
343-
} catch (InvalidArgumentException $e) {
343+
} catch (InvalidArgumentException|iException $e) {
344344
return new Response(
345345
status: false,
346346
error: new Error(
@@ -377,7 +377,7 @@ private function getExternalUsers(Context $context, array $opts = []): Response
377377
'Accept' => 'application/xml',
378378
],
379379
]);
380-
} catch (InvalidArgumentException $e) {
380+
} catch (InvalidArgumentException|iException $e) {
381381
return new Response(
382382
status: false,
383383
error: new Error(

0 commit comments

Comments
 (0)