@@ -, +, @@ --- debian/templates/plack.psgi | 21 ++++++++++++++++++++- errors/400.pl | 7 ++++++- errors/401.pl | 7 ++++++- errors/402.pl | 7 ++++++- errors/403.pl | 7 ++++++- errors/404.pl | 23 ++++++++++++++++++++++- errors/500.pl | 7 ++++++- opac/errors/400.pl | 7 ++++++- opac/errors/401.pl | 7 ++++++- opac/errors/402.pl | 7 ++++++- opac/errors/403.pl | 7 ++++++- opac/errors/404.pl | 7 ++++++- opac/errors/500.pl | 7 ++++++- 13 files changed, 108 insertions(+), 13 deletions(-) --- a/debian/templates/plack.psgi +++ a/debian/templates/plack.psgi @@ -76,8 +76,17 @@ builder { # + is required so Plack doesn't try to prefix Plack::Middleware:: enable "+Koha::Middleware::SetEnv"; enable "+Koha::Middleware::RealIP"; - mount '/opac' => builder { + #NOTE: it is important that these are relative links + enable 'ErrorDocument', + 400 => 'errors/400.pl', + 401 => 'errors/401.pl', + 402 => 'errors/402.pl', + 403 => 'errors/403.pl', + 404 => 'errors/404.pl', + 500 => 'errors/500.pl', + subrequest => 1; + enable 'StackTrace', no_print_errors => 1; #NOTE: StackTrace must follow ErrorDocument or 500 won't work if ( Log::Log4perl->get_logger('plack-opac')->has_appenders ){ enable 'Log4perl', category => 'plack-opac'; enable 'LogWarn'; @@ -85,6 +94,16 @@ builder { $opac; }; mount '/intranet' => builder { + #NOTE: it is important that these are relative links + enable 'ErrorDocument', + 400 => 'errors/400.pl', + 401 => 'errors/401.pl', + 402 => 'errors/402.pl', + 403 => 'errors/403.pl', + 404 => 'errors/404.pl', + 500 => 'errors/500.pl', + subrequest => 1; + enable 'StackTrace', no_print_errors => 1; #NOTE: StackTrace must follow ErrorDocument or 500 won't work if ( Log::Log4perl->get_logger('plack-intranet')->has_appenders ){ enable 'Log4perl', category => 'plack-intranet'; enable 'LogWarn'; --- a/errors/400.pl +++ a/errors/400.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -37,4 +38,8 @@ $template->param ( admin => $admin, errno => 400, ); -output_with_http_headers $query, $cookie, $template->output, 'html', '400 Bad Request'; +my $status = '400 Bad Request'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/errors/401.pl +++ a/errors/401.pl @@ -20,6 +20,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -36,4 +37,8 @@ $template->param ( admin => $admin, errno => 401, ); -output_with_http_headers $query, $cookie, $template->output, 'html', '401 Unauthorized'; +my $status = '401 Unauthorized'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/errors/402.pl +++ a/errors/402.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -37,4 +38,8 @@ $template->param ( admin => $admin, errno => 402, ); -output_with_http_headers $query, $cookie, $template->output, 'html', '402 Payment Required'; +my $status = '402 Payment Required'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/errors/403.pl +++ a/errors/403.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -37,4 +38,8 @@ $template->param ( admin => $admin, errno => 403, ); -output_with_http_headers $query, $cookie, $template->output, 'html', '403 Forbidden'; +my $status = '403 Forbidden'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/errors/404.pl +++ a/errors/404.pl @@ -18,7 +18,28 @@ use Modern::Perl; use CGI qw ( -utf8 ); +use C4::Auth; use C4::Output; +use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; -output_error( $query, '404' ); +my $admin = C4::Context->preference('KohaAdminEmailAddress'); +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => 'errors/errorpage.tt', + query => $query, + type => 'intranet', + authnotrequired => 1, + debug => 1, + } +); +$template->param ( + admin => $admin, + errno => 404, +); +my $status = '404 Not Found'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/errors/500.pl +++ a/errors/500.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -37,4 +38,8 @@ $template->param ( admin => $admin, errno => 500, ); -output_with_http_headers $query, $cookie, $template->output, 'html', '500 Internal Server Error'; +my $status = '500 Internal Server Error'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/400.pl +++ a/opac/errors/400.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -37,4 +38,8 @@ $template->param ( admin => $admin, errno => 400, ); -output_with_http_headers $query, $cookie, $template->output, 'html', '400 Bad Request'; +my $status = '400 Bad Request'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/401.pl +++ a/opac/errors/401.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -37,4 +38,8 @@ $template->param ( admin => $admin, errno => 401, ); -output_with_http_headers $query, $cookie, $template->output, 'html', '401 Unauthorized'; +my $status = '401 Unauthorized'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/402.pl +++ a/opac/errors/402.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -37,4 +38,8 @@ $template->param ( admin => $admin, errno => 402, ); -output_with_http_headers $query, $cookie, $template->output, 'html', '402 Payment Required'; +my $status = '402 Payment Required'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/403.pl +++ a/opac/errors/403.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -37,4 +38,8 @@ $template->param ( admin => $admin, errno => 403, ); -output_with_http_headers $query, $cookie, $template->output, 'html', '403 Forbidden'; +my $status = '403 Forbidden'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/404.pl +++ a/opac/errors/404.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -37,4 +38,8 @@ $template->param ( admin => $admin, errno => 404, ); -output_html_with_http_headers $query, $cookie, $template->output, '404 Not Found'; +my $status = '404 Not Found'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/500.pl +++ a/opac/errors/500.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; +use List::MoreUtils qw(any); my $query = CGI->new; my $admin = C4::Context->preference('KohaAdminEmailAddress'); @@ -37,4 +38,8 @@ $template->param ( admin => $admin, errno => 500, ); -output_with_http_headers $query, $cookie, $template->output, 'html', '500 Internal Server Error'; +my $status = '500 Internal Server Error'; +if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $status = '200 OK'; +} +output_with_http_headers $query, $cookie, $template->output, 'html', $status; --