Bug 27945: Fix error handling and translatability
This patch adds better error handling and reporting when placing an article request fails. It also makes the error messages translatable. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
2c4fa722df
commit
82155cdf35
4 changed files with 48 additions and 15 deletions
|
@ -25,8 +25,11 @@ use C4::Utils::DataTables::Members;
|
|||
use C4::Search qw( enabled_staff_search_views );
|
||||
use C4::Serials qw( CountSubscriptionFromBiblionumber );
|
||||
use Koha::Biblios;
|
||||
use Koha::Logger;
|
||||
use Koha::Patrons;
|
||||
use Koha::ArticleRequests;
|
||||
|
||||
use Scalar::Util qw( blessed );
|
||||
use Try::Tiny;
|
||||
|
||||
my $cgi = CGI->new;
|
||||
|
@ -86,11 +89,19 @@ if ( $action eq 'create' ) {
|
|||
patron_notes => $patron_notes,
|
||||
format => $format,
|
||||
}
|
||||
)->store();
|
||||
)->request;
|
||||
} catch {
|
||||
$template->param(
|
||||
error_message => $_->{message}
|
||||
);
|
||||
if ( blessed $_ and $_->isa('Koha::Exceptions::ArticleRequest::LimitReached') ) {
|
||||
$template->param(
|
||||
error_message => 'article_request_limit_reached'
|
||||
);
|
||||
}
|
||||
else {
|
||||
Koha::Logger->get->debug("Unhandled exception when placing an article request ($_)");
|
||||
$template->param(
|
||||
error_message => 'article_request_unhandled_exception'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -119,7 +130,7 @@ if ( !$patron && $patron_cardnumber ) {
|
|||
if( $patron && !$patron->can_request_article) {
|
||||
$patron = undef;
|
||||
$template->param(
|
||||
error_message => 'Patron cannot request more articles for today'
|
||||
error_message => 'article_request_limit_reached'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,10 @@
|
|||
<h1>Request article from [% INCLUDE 'biblio-title.inc' link = 1 %]</h1>
|
||||
[% IF error_message %]
|
||||
<div class="dialog alert">
|
||||
<p>[% error_message | html %]</p>
|
||||
[% SWITCH error_message %]
|
||||
[% CASE 'article_request_limit_reached' %]<p>Patron reached daily limit.</p>
|
||||
[% CASE 'article_request_unhandled_exception' %]<p>An error has occurred. Check the logs.</p>
|
||||
[% END %]
|
||||
</div>
|
||||
[% END %]
|
||||
[% IF no_patrons_found %]
|
||||
|
|
|
@ -219,7 +219,10 @@
|
|||
[% ELSIF error_message %]
|
||||
<h1 class="title">[% biblio.title | html %]</h1>
|
||||
<div class="alert alert-info">
|
||||
[% error_message | html %]
|
||||
[% SWITCH error_message %]
|
||||
[% CASE 'article_request_limit_reached' %]You reached your article requests daily limit.
|
||||
[% CASE 'article_request_unhandled_exception' %]An error has occurred.
|
||||
[% END %]
|
||||
</div>
|
||||
[% ELSE %]
|
||||
<h1 class="title">[% biblio.title | html %]</h1>
|
||||
|
|
|
@ -25,7 +25,10 @@ use C4::Auth qw( get_template_and_user );
|
|||
use C4::Output qw( output_html_with_http_headers );
|
||||
|
||||
use Koha::Biblios;
|
||||
use Koha::Logger;
|
||||
use Koha::Patrons;
|
||||
|
||||
use Scalar::Util qw( blessed );
|
||||
use Try::Tiny;
|
||||
|
||||
my $cgi = CGI->new;
|
||||
|
@ -60,6 +63,9 @@ if ( $action eq 'create' ) {
|
|||
my $patron_notes = $cgi->param('patron_notes') || undef;
|
||||
my $format = $cgi->param('format') || undef;
|
||||
|
||||
|
||||
my $success;
|
||||
|
||||
try {
|
||||
my $ar = Koha::ArticleRequest->new(
|
||||
{
|
||||
|
@ -77,16 +83,26 @@ if ( $action eq 'create' ) {
|
|||
patron_notes => $patron_notes,
|
||||
format => $format,
|
||||
}
|
||||
)->store();
|
||||
)->request;
|
||||
$success = 1;
|
||||
} catch {
|
||||
if ( blessed $_ and $_->isa('Koha::Exceptions::ArticleRequest::LimitReached') ) {
|
||||
$template->param(
|
||||
error_message => 'article_request_limit_reached'
|
||||
);
|
||||
}
|
||||
else {
|
||||
Koha::Logger->get->debug("Unhandled exception when placing an article request ($_)");
|
||||
$template->param(
|
||||
error_message => 'article_request_unhandled_exception'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if ( $success ) {
|
||||
print $cgi->redirect("/cgi-bin/koha/opac-user.pl#opac-user-article-requests");
|
||||
exit;
|
||||
} catch {
|
||||
exit unless $_->[0] && $_->[0] eq 'EXIT';
|
||||
$template->param(
|
||||
error_message => $_->{message}
|
||||
);
|
||||
};
|
||||
}
|
||||
# Should we redirect?
|
||||
}
|
||||
elsif ( !$action && C4::Context->preference('ArticleRequestsOpacHostRedirection') ) {
|
||||
|
@ -106,7 +122,7 @@ my $patron = Koha::Patrons->find($borrowernumber);
|
|||
|
||||
if(!$patron->can_request_article) {
|
||||
$template->param(
|
||||
error_message => 'You cannot request more articles for today'
|
||||
error_message => 'article_request_limit_reached'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue