use Scalar::Util qw( blessed );
-use Try::Tiny;
+use Try::Tiny qw( catch try );
=head1 NAME
return $c->render( status => 200, openapi => $libraries );
}
catch {
- unless ( blessed $_ && $_->can('rethrow') ) {
- return $c->render(
- status => 500,
- openapi => { error => "Something went wrong, check Koha logs for details." }
- );
- }
- return $c->render(
- status => 500,
- openapi => { error => "$_" }
- );
+ $c->unhandled_exception($_);
};
}
sub get {
my $c = shift->openapi->valid_input or return;
- my $library_id = $c->validation->param('library_id');
- my $library = Koha::Libraries->find( $library_id );
+ return try {
+ my $library_id = $c->validation->param('library_id');
+ my $library = Koha::Libraries->find( $library_id );
- unless ($library) {
- return $c->render( status => 404,
- openapi => { error => "Library not found" } );
- }
+ unless ($library) {
+ return $c->render( status => 404,
+ openapi => { error => "Library not found" } );
+ }
- return $c->render(
- status => 200,
- openapi => $library->to_api
- );
+ return $c->render(
+ status => 200,
+ openapi => $library->to_api
+ );
+ }
+ catch {
+ $c->unhandled_exception($_);
+ };
}
=head3 add
);
}
catch {
- unless ( blessed $_ && $_->can('rethrow') ) {
- return $c->render(
- status => 500,
- openapi => { error => "Something went wrong, check Koha logs for details." }
- );
- }
- if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
+ if ( blessed $_ && $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
return $c->render(
status => 409,
openapi => { error => $_->error, conflict => $_->duplicate_id }
);
}
- else {
- return $c->render(
- status => 500,
- openapi => { error => "$_" }
- );
- }
+
+ $c->unhandled_exception($_);
};
}
);
}
catch {
- unless ( blessed $_ && $_->can('rethrow') ) {
- return $c->render(
- status => 500,
- openapi => { error => "Something went wrong, check Koha logs for details." }
- );
- }
-
- return $c->render(
- status => 500,
- openapi => { error => "$_" }
- );
+ $c->unhandled_exception($_);
};
}
return $c->render( status => 204, openapi => '');
}
catch {
- unless ( blessed $_ && $_->can('rethrow') ) {
- return $c->render(
- status => 500,
- openapi => { error => "Something went wrong, check Koha logs for details." }
- );
- }
-
- return $c->render(
- status => 500,
- openapi => { error => "$_" }
- );
+ $c->unhandled_exception($_);
};
}