Skip to content

Commit

Permalink
feat: improved error message response (#3296)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Dec 21, 2024
1 parent 4636431 commit 7ece84a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
20 changes: 13 additions & 7 deletions phpmyfaq/assets/src/configuration/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,17 @@ export const handleDatabaseUpdate = async () => {
alert.classList.remove('d-none');
return;
} else {
const value = JSON.parse(decodedValue);
let value;
try {
value = JSON.parse(decodedValue);
} catch (error) {
console.error('Failed to parse JSON:', error);
const alert = document.getElementById('phpmyfaq-update-database-error');
const errorMessage = document.getElementById('error-messages');
alert.classList.remove('d-none');
errorMessage.innerText = `Error: ${error.message}\nFull Error: ${decodedValue}`;
return;
}
if (value.progress) {
progressBarInstallation.style.width = value.progress;
progressBarInstallation.innerText = value.progress;
Expand All @@ -147,14 +157,10 @@ export const handleDatabaseUpdate = async () => {

await pump();
} catch (error) {
const errorMessage =
error.cause && error.cause.response
? await error.cause.response.json()
: { error: 'Unknown database error during update.' };
console.error('Error details:', error);
const alert = document.getElementById('phpmyfaq-update-database-error');

alert.classList.remove('d-none');
alert.innerHTML = errorMessage.error;
alert.innerText = `Error: ${error.message}`;
}
}
};
2 changes: 1 addition & 1 deletion phpmyfaq/assets/templates/setup/index.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'setup/base.twig' %}
{% extends '@setup/base.twig' %}

{% block content %}
<main role="main">
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/assets/templates/setup/update.twig
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<span class="stepIndicator">Database updates</span>
</div>

{{ include('./setup/update/step' ~ currentStep ~ '.twig') }}
{{ include('@setup/update/step' ~ currentStep ~ '.twig') }}

{% if checkBasicError %}
<div class="alert alert-danger my-5" role="alert">
Expand Down
6 changes: 3 additions & 3 deletions phpmyfaq/src/phpMyFAQ/Controller/Frontend/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function index(Request $request): Response
}

return $this->render(
'setup/index.twig',
'@setup/index.twig',
[
'newVersion' => System::getVersion(),
'setupType' => 'Setup',
Expand Down Expand Up @@ -95,7 +95,7 @@ public function install(): Response
}

return $this->render(
'setup/install.twig',
'@setup/install.twig',
[
'newVersion' => System::getVersion(),
'setupType' => 'Setup',
Expand Down Expand Up @@ -128,7 +128,7 @@ public function update(Request $request): Response
}

return $this->render(
'setup/update.twig',
'@setup/update.twig',
[
'currentStep' => $currentStep ?? 1,
'installedVersion' => $configuration->getVersion(),
Expand Down
1 change: 1 addition & 0 deletions phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function __construct(string $templatePath, bool $isSetup = false)
$filesystemLoader = new FilesystemLoader();
$filesystemLoader->addPath($templatePath . '/' . self::$templateSetName);
$filesystemLoader->addPath($templatePath . '/admin', 'admin');
$filesystemLoader->addPath($templatePath . '/setup', 'setup');
$this->twigEnvironment = new Environment(
$filesystemLoader,
[
Expand Down

0 comments on commit 7ece84a

Please sign in to comment.