getMessage()) { default: throw $err; } } } public function patch($id): void { $content = Input::patch("content"); $self = User::getByToken(Request::token()); $post = MPost::getByID($id); if (!$self->getIsAdmin() && $post->getUser()->getID() !== $self->getID()) throw new Exception("Not Authorized", 401); try { Response::json(MPost::getByID($id)->update($content)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": throw new Exception("Post not found", 404); case "FailedContent": throw new Exception("Failed to update content", 500); default: throw $err; } } } public function delete($id): void { try { Response::json(MPost::getByID($id)->delete()); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": throw new Exception("Post not found", 404); default: throw $err; } } } }