Skip to content

Commit e6ea9fc

Browse files
authored
Improve exception handling and logging (#57)
* increase productio worker count * improve exceptoin handling and logging * adjust message * fix stan error * include status code changes in exception
1 parent dc64e65 commit e6ea9fc

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

app/Jobs/UpdateSite.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ public function handle(): void
5454
$connection = $this->site->connection;
5555

5656
// Test connection and get current version
57-
$healthResult = $connection->checkHealth();
57+
try {
58+
$healthResult = $connection->checkHealth();
59+
} catch (\Throwable $e) {
60+
throw new UpdateException(
61+
"checkHealth",
62+
$e->getMessage(),
63+
(int) $e->getCode(),
64+
$e instanceof \Exception ? $e : null
65+
);
66+
}
5867

5968
// Check the version
6069
if (version_compare($healthResult->cms_version, $this->targetVersion, ">=")) {
@@ -106,7 +115,16 @@ public function handle(): void
106115
return;
107116
}
108117

109-
$prepareResult = $connection->prepareUpdate(["targetVersion" => $this->targetVersion]);
118+
try {
119+
$prepareResult = $connection->prepareUpdate(["targetVersion" => $this->targetVersion]);
120+
} catch (\Throwable $e) {
121+
throw new UpdateException(
122+
"prepareUpdate",
123+
$e->getMessage(),
124+
(int) $e->getCode(),
125+
$e instanceof \Exception ? $e : null
126+
);
127+
}
110128

111129
// Perform the actual extraction
112130
try {
@@ -139,7 +157,12 @@ public function handle(): void
139157
if ($afterUpdateCode !== $this->preUpdateCode) {
140158
throw new UpdateException(
141159
"afterUpdate",
142-
"Status code has changed after update for site: " . $this->site->id
160+
sprintf(
161+
"Status code has changed from %s to %s after update for site: %s",
162+
$this->preUpdateCode,
163+
$afterUpdateCode,
164+
$this->site->id
165+
)
143166
);
144167
}
145168

@@ -213,10 +236,19 @@ public function failed(\Exception $exception): void
213236
$connection = $this->site->connection;
214237

215238
// Get base execption information
216-
$failedStep = $exception instanceof UpdateException ? $exception->getStep() : null;
239+
$failedStep = $exception instanceof UpdateException ? $exception->getStep() : get_class($exception);
217240
$failedMessage = $exception->getMessage();
218241
$failedTrace = $exception->getTraceAsString();
219242

243+
// Log response body
244+
if ($exception instanceof RequestException) {
245+
$failedMessage .= "\n Response Body: " . $exception->getResponse()?->getBody();
246+
}
247+
248+
if ($exception->getPrevious() instanceof RequestException) {
249+
$failedMessage .= "\n Response Body: " . $exception->getPrevious()->getResponse()?->getBody();
250+
}
251+
220252
// Notify users
221253
try {
222254
$connection->notificationFailed(["fromVersion" => $this->site->cms_version, "toVersion" => $this->targetVersion]);

0 commit comments

Comments
 (0)