|
Lines 15-21
package Koha::Schema::Util::ExceptionTranslator;
Link Here
|
| 15 |
# GNU General Public License for more details. |
15 |
# GNU General Public License for more details. |
| 16 |
# |
16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
|
Lines 80-86
If the exception cannot be translated, it rethrows the original exception.
Link Here
|
| 80 |
=cut |
80 |
=cut |
| 81 |
|
81 |
|
| 82 |
sub translate_exception { |
82 |
sub translate_exception { |
| 83 |
my ( $class, $exception, $columns_info ) = @_; |
83 |
my ( $class, $exception, $columns_info, $object ) = @_; |
| 84 |
|
84 |
|
| 85 |
# Only handle DBIx::Class exceptions |
85 |
# Only handle DBIx::Class exceptions |
| 86 |
return $exception->rethrow() unless ref($exception) eq 'DBIx::Class::Exception'; |
86 |
return $exception->rethrow() unless ref($exception) eq 'DBIx::Class::Exception'; |
|
Lines 148-159
sub translate_exception {
Link Here
|
| 148 |
if ( $columns_info && $columns_info->{$property} ) { |
148 |
if ( $columns_info && $columns_info->{$property} ) { |
| 149 |
my $type = $columns_info->{$property}->{data_type}; |
149 |
my $type = $columns_info->{$property}->{data_type}; |
| 150 |
if ( $type && $type eq 'enum' ) { |
150 |
if ( $type && $type eq 'enum' ) { |
|
|
151 |
my $value = 'Invalid enum value'; # Default value |
| 152 |
|
| 153 |
# If we have an object, try to get the actual property value |
| 154 |
if ( $object && $object->can($property) ) { |
| 155 |
eval { $value = $object->$property; }; |
| 156 |
} |
| 157 |
|
| 151 |
Koha::Exceptions::Object::BadValue->throw( |
158 |
Koha::Exceptions::Object::BadValue->throw( |
| 152 |
type => 'enum', |
159 |
type => 'enum', |
| 153 |
property => $property =~ /(\w+\.\w+)$/ |
160 |
property => $property =~ /(\w+\.\w+)$/ |
| 154 |
? $1 |
161 |
? $1 |
| 155 |
: $property, # results in table.column without quotes or backticks |
162 |
: $property, # results in table.column without quotes or backticks |
| 156 |
value => 'Invalid enum value', # We don't have access to the object here |
163 |
value => $value, |
| 157 |
); |
164 |
); |
| 158 |
} |
165 |
} |
| 159 |
} |
166 |
} |