Skip to content

Commit 7fa7df5

Browse files
Avoid fatal error when Rest request fails in Package Browser (#16738)
### What does it do? Better error handling in the `Workspace/Packages/Rest/GetList` processor. ### Why is it needed? While searching for extras in the "Package Browser", the code throws a fatal error when there is a problem with the connection. ``` Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given ``` --- The `find()` function of the class `modTransportProvider` returns a string if there is a error: https://github.com/modxcms/revolution/blob/11d96669133bab7f1095c96be63368f841d8dbd7/core/src/Revolution/Transport/modTransportProvider.php#L333
1 parent 11d9666 commit 7fa7df5

File tree

1 file changed

+3
-1
lines changed
  • core/src/Revolution/Processors/Workspace/Packages/Rest

1 file changed

+3
-1
lines changed

core/src/Revolution/Processors/Workspace/Packages/Rest/GetList.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ public function process()
7373
{
7474
$data = $this->provider->find($this->getProperties());
7575

76-
if (empty($data) || count($data) !== 2) {
76+
if (is_string($data)){
77+
return $this->failure($data);
78+
} elseif (!(is_array($data) && count($data) === 2)) {
7779
return $this->failure($this->modx->lexicon('provider_err_connect'));
7880
}
7981

0 commit comments

Comments
 (0)