Skip to content

Commit

Permalink
Improve cloud error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Sep 29, 2020
1 parent 0af9f32 commit 469ae37
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions api/TaskOperation/Composer/CloudOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ public function getDetails(): ?string

public function getConsole(): ConsoleOutput
{
$console = new ConsoleOutput();
$job = $this->getCurrentJob();

if ($this->exception instanceof CloudException) {
return (new ConsoleOutput())->add(
return $console->add(
sprintf(
"> The Composer Resolver Cloud failed with status code %s\n\n %s",
$this->exception->getStatusCode(),
Expand All @@ -157,18 +158,21 @@ public function getConsole(): ConsoleOutput
}

if ($this->exception instanceof RequestException && 404 === $this->exception->getStatusCode()) {
return (new ConsoleOutput())->add(self::CLOUD_ERROR);
return $console->add(self::CLOUD_ERROR);
}

if ($this->exception instanceof \Exception) {
return (new ConsoleOutput())->add($this->exception->getMessage());
return $console->add($this->exception->getMessage());
}

if (!$job instanceof CloudJob) {
return new ConsoleOutput();
if ($this->hasError()) {
$console->add(self::CLOUD_ERROR);
}

return $console;
}

$console = new ConsoleOutput();
$title = '> Resolving dependencies using Composer Cloud '.$job->getVersion();
// $title .= "\n!!! Current server is sponsored by: ".$job->getSponsor()." !!!\n";

Expand Down Expand Up @@ -248,7 +252,7 @@ public function run(): void
// Retry to create Cloud job, the first request always fails on XAMPP for unknown reason
$attempts = $this->taskConfig->getState('cloud-job-attempts', 0);

if ($attempts >= 2) {
if ($attempts >= 5) {
$this->taskConfig->setState('cloud-job-successful', false);
$this->output = self::CLOUD_ERROR;

Expand Down Expand Up @@ -308,6 +312,10 @@ private function getCurrentJob(): ?CloudJob
return $this->job;
}

if (null === $this->taskConfig->getState('cloud-job')) {
return null;
}

try {
if ($content = $this->taskConfig->getState('cloud-job-status')) {
$this->job = new CloudJob(JsonFile::parseJson($content));
Expand Down

0 comments on commit 469ae37

Please sign in to comment.