Skip to content

Commit 7d20e30

Browse files
committed
Enhanced error handling
1 parent bdc0fb1 commit 7d20e30

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

Diff for: src/controllers/PackageController.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,26 @@ public function actionUpdate()
3838
Yii::createObject(PackageUpdateCommand::class, [$package])->run();
3939
} catch (UpdateRateLimitException $exception) {
4040
Yii::$app->session->addFlash('rate-limited', true);
41-
} catch (\Composer\Downloader\TransportException $exception) {
42-
if (stripos($exception->getMessage(), 'not found')) {
41+
} catch (\Composer\Downloader\TransportException $e) {
42+
if (stripos($e->getMessage(), 'not found')) {
43+
Yii::warning('Failed to update ' . $package->getFullName() . ': ' . $e->getMessage(), __METHOD__);
44+
4345
return $this->renderPartial('not-found', ['package' => $package]);
4446
}
4547

46-
return $this->renderPartial('transport-error');
48+
throw $e;
49+
} catch (\Composer\Repository\InvalidRepositoryException $e) {
50+
Yii::warning('Failed to update ' . $package->getFullName() . ': ' . $e->getMessage(), __METHOD__);
51+
52+
return $this->renderPartial('fetch-error', ['package' => $package, 'exception' => $e]);
53+
} catch (Exception $e) {
54+
Yii::error([
55+
'UNKNOWN error during ' . $package->getFullName() . ' update',
56+
get_class($e),
57+
$e->getMessage(),
58+
], __METHOD__);
59+
60+
return $this->renderPartial('fetch-error', ['package' => $package, 'exception' => $e]);
4761
}
4862

4963
$package->load();

Diff for: src/views/package/details.php

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
<?php
1212
$releases = $package->getReleases();
13-
ksort($releases);
14-
$releases = array_reverse($releases);
1513
?>
1614

1715
<div class="versions">

Diff for: src/views/package/fetch-error.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* @var \yii\web\View $this
5+
* @var \hiqdev\assetpackagist\models\AssetPackage $package
6+
* @var \Composer\Repository\InvalidRepositoryException $exception
7+
*/
8+
9+
use yii\helpers\Html;
10+
11+
$this->title = 'Package update failed';
12+
13+
?>
14+
<hr/>
15+
<h3><?= $this->title ?></h3>
16+
17+
<blockquote><?= $exception->getMessage() ?></blockquote>
18+
19+
<?php
20+
21+
if ($package->getType() === 'npm') {
22+
$link = Html::a('npmjs.com', 'https://npmjs.com/search?q=' . $package->getName(), ['target' => '_blank']);
23+
} elseif ($package->getType() === 'bower') {
24+
$link = Html::a('bower.io', 'https://bower.io/search?q=' . $package->getName(), ['target' => '_blank']);
25+
}
26+
27+
?>
28+
29+
<h4>Could you ensure this package exists on <?= $link ?> ?</h4>
30+
<p>Think asset-packagist is guilty? <?= Html::a('Report on GitHub', 'https://github.com/hiqdev/asset-packagist/issues/new') ?>
31+
</p>

0 commit comments

Comments
 (0)