Better Errors
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user