Better Errors

This commit is contained in:
2024-07-23 01:12:05 +02:00
parent 30849019af
commit 85d20e034a
18 changed files with 567 additions and 390 deletions
+6 -3
View File
@@ -7,6 +7,7 @@ use DateTime;
use Exception;
use Khofmann\Models\User\User;
use JsonSerializable;
use Khofmann\ApiError\ApiError;
use Khofmann\Database\Database;
use PDO;
@@ -113,14 +114,16 @@ class Post implements JsonSerializable
{
$db = Database::getInstance();
$error = false;
if (!empty($content)) {
$stmt = $db->prepare("UPDATE egb_gaestebuch SET beitrag = :CON WHERE id = :ID");
$stmt->bindValue(":CON", $content);
$stmt->bindValue(":ID", $this->id);
$error = !$stmt->execute();
try {
if (!$stmt->execute()) throw ApiError::failedUpdate(["content"]);
} catch (Exception $e) {
throw ApiError::failedUpdate(["content"]);
}
}
if ($error) throw new Exception("FailedContent");
return Post::getByID($this->id);
}