getIsAdmin() && $post->getUser()->getID() !== $self->getID()) throw ApiError::unauthorized("Not allowed"); // Try update. Response::json($post->update($content)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": throw ApiError::notFound("post"); default: // Due to how the failed field is handled, it's ApiError is inside the models update throw $err; } } } public function delete($id): void { // Try delete, 404 if post was not found. try { Response::json(MPost::getByID($id)->delete()); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": throw ApiError::notFound("post"); default: throw $err; } } } }