From e453ff963af6b8f868b7262d32de274c89c582ab Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 30 Mar 2021 11:03:09 -0300 Subject: [PATCH] Bug 27857: (follow-up) Use a more fine-grained exception for mandatory attributes On using this dev for the API, I found that the original FKConstraint exception was too generic, and could be confused with those risen by Koha::Patron->store. So this patch changes the exception that is thrown in Koha::Patron->extended_attributes The change is reflected on the test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Patron.t => SUCCESS: Tests pass, and they include the new exception 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- Koha/Patron.pm | 5 ++--- t/db_dependent/Koha/Patron.t | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index be83c399ce..7630ce72a5 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1578,9 +1578,8 @@ sub extended_attributes { { join => 'borrower_attribute_types_branches' } )->get_column('code'); for my $type ( @required_attribute_types ) { - Koha::Exceptions::Object::FKConstraint->throw( - broken_fk => "$type", - value => "$type", + Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute->throw( + type => $type, ) if !$new_types->{$type}; } } diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index bf211af98e..a645eb37d9 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -644,7 +644,7 @@ subtest 'extended_attributes' => sub { ] ); } - 'Koha::Exceptions::Object::FKConstraint', + 'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute', 'Exception thrown on missing mandatory attribute type'; is( $@->value, $attribute_type_1->code, 'Exception parameters are correct' ); -- 2.39.5