From c36d1ac3d3377c352112f7377dc7c6b70a33f38b Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Thu, 9 Jan 2025 14:08:54 -0600 Subject: [PATCH] Rename exception for consistency --- lib/Ebook.php | 10 +++++----- ...cateEbookException.php => EbookExistsException.php} | 2 +- www/ebook-placeholders/post.php | 4 ++-- www/projects/post.php | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) rename lib/Exceptions/{DuplicateEbookException.php => EbookExistsException.php} (79%) diff --git a/lib/Ebook.php b/lib/Ebook.php index b3477f5c..c4cb29c3 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -1550,7 +1550,7 @@ final class Ebook{ /** * @throws Exceptions\InvalidEbookException - * @throws Exceptions\DuplicateEbookException + * @throws Exceptions\EbookExistsException */ public function CreateOrUpdate(): void{ try{ @@ -1838,14 +1838,14 @@ final class Ebook{ /** * @throws Exceptions\InvalidEbookException - * @throws Exceptions\DuplicateEbookException If an `Ebook` with the given identifier already exists. + * @throws Exceptions\EbookExistsException If an `Ebook` with the given identifier already exists. */ public function Create(): void{ $this->Validate(); try{ Ebook::GetByIdentifier($this->Identifier); - throw new Exceptions\DuplicateEbookException($this->Identifier); + throw new Exceptions\EbookExistsException($this->Identifier); } catch(Exceptions\EbookNotFoundException){ // Pass. @@ -1917,7 +1917,7 @@ final class Ebook{ /** * @throws Exceptions\InvalidEbookException If the `Ebook` is invalid. - * @throws Exceptions\DuplicateEbookException If an `Ebook` with the same title and author already exists. + * @throws Exceptions\EbookExistsException If an `Ebook` with the same title and author already exists. */ public function Save(): void{ $this->Validate(); @@ -1970,7 +1970,7 @@ final class Ebook{ $this->EbookId]); } catch(Exceptions\DuplicateDatabaseKeyException){ - throw new Exceptions\DuplicateEbookException($this->Identifier); + throw new Exceptions\EbookExistsException($this->Identifier); } diff --git a/lib/Exceptions/DuplicateEbookException.php b/lib/Exceptions/EbookExistsException.php similarity index 79% rename from lib/Exceptions/DuplicateEbookException.php rename to lib/Exceptions/EbookExistsException.php index dc575c8b..9b5c79c6 100644 --- a/lib/Exceptions/DuplicateEbookException.php +++ b/lib/Exceptions/EbookExistsException.php @@ -1,7 +1,7 @@ message = 'Ebook already exists with identifier: ' . $identifier; diff --git a/www/ebook-placeholders/post.php b/www/ebook-placeholders/post.php index a11894ba..a6f5a18a 100644 --- a/www/ebook-placeholders/post.php +++ b/www/ebook-placeholders/post.php @@ -34,7 +34,7 @@ try{ try{ $ebook->Create(); } - catch(Exceptions\DuplicateEbookException $ex){ + catch(Exceptions\EbookExistsException $ex){ $ebook = Ebook::GetByIdentifier($ebook->Identifier); // An existing `EbookPlaceholder` already exists. @@ -72,7 +72,7 @@ try{ try{ $ebook->Save(); } - catch(Exceptions\DuplicateEbookException){ + catch(Exceptions\EbookExistsException){ throw new Exceptions\EbookPlaceholderExistsException(); } diff --git a/www/projects/post.php b/www/projects/post.php index 84177ac6..10ae60ca 100644 --- a/www/projects/post.php +++ b/www/projects/post.php @@ -35,7 +35,7 @@ try{ $project->Ebook->Create(); $project->EbookId = $project->Ebook->EbookId; } - catch(Exceptions\DuplicateEbookException $ex){ + catch(Exceptions\EbookExistsException $ex){ // If the `Ebook` already exists, create the `Project` anyway. $project->Ebook = Ebook::GetByIdentifier($project->Ebook->Identifier); if($project->Ebook->EbookPlaceholder !== null && !$project->Ebook->EbookPlaceholder->IsInProgress){ @@ -90,7 +90,7 @@ catch(Exceptions\LoginRequiredException){ catch(Exceptions\InvalidPermissionsException){ Template::ExitWithCode(Enums\HttpCode::Forbidden); } -catch(Exceptions\InvalidProjectException | Exceptions\InvalidEbookException | Exceptions\ProjectExistsException | Exceptions\DuplicateEbookException | Exceptions\EbookIsNotAPlaceholderException $ex){ +catch(Exceptions\InvalidProjectException | Exceptions\InvalidEbookException | Exceptions\ProjectExistsException | Exceptions\EbookExistsException | Exceptions\EbookIsNotAPlaceholderException $ex){ $_SESSION['project'] = $project; $_SESSION['exception'] = $ex;