From f234940fa09cd657a69654fef36617a6a231ced1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 20 Jan 2021 15:13:10 +0100 Subject: [PATCH] Bug 26048: POC - use ErrorDocument for 500 Proof of concept to use ErrorDocument to handle our 500. This is not ready at all, we need to tweak the mount and enable statements to make it possible to have a separate 500 for OPAC and intranet To test you need to: 1. Edit /usr/sbin/koha-plack Force environment to be set to deployment 109 environment="deployment"; 2. Add a die somewhere and hit the page --- debian/templates/plack.psgi | 64 ++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/debian/templates/plack.psgi b/debian/templates/plack.psgi index 99438c595a..8bdc67347b 100644 --- a/debian/templates/plack.psgi +++ b/debian/templates/plack.psgi @@ -36,9 +36,7 @@ use Koha::Caches; use Koha::Cache::Memory::Lite; use Koha::Database; use Koha::DateUtils; -use Koha::Logger; -use Log::Log4perl; use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise { no warnings 'redefine'; @@ -67,8 +65,6 @@ my $apiv1 = builder { $server->to_psgi_app; }; -Koha::Logger->_init; - builder { enable "ReverseProxy"; enable "Plack::Middleware::Static"; @@ -77,25 +73,43 @@ builder { enable "+Koha::Middleware::SetEnv"; enable "+Koha::Middleware::RealIP"; - mount '/opac' => builder { - if ( Log::Log4perl->get_logger('plack-opac')->has_appenders ){ - enable 'Log4perl', category => 'plack-opac'; - enable 'LogWarn'; - } - $opac; - }; - mount '/intranet' => builder { - if ( Log::Log4perl->get_logger('plack-intranet')->has_appenders ){ - enable 'Log4perl', category => 'plack-intranet'; - enable 'LogWarn'; - } - $intranet; - }; - mount '/api/v1/app.pl' => builder { - if ( Log::Log4perl->get_logger('plack-api')->has_appenders ){ - enable 'Log4perl', category => 'plack-api'; - enable 'LogWarn'; - } - $apiv1; - }; + enable 'ErrorDocument', 500, '/errors', subrequest => 1; + enable 'StackTrace', no_print_errors => 1; + + mount '/opac' => $opac; + mount '/intranet' => $intranet; + mount '/api/v1/app.pl' => $apiv1; + + mount '/errors' => sub { + my $env = shift; + + use CGI qw ( -utf8 ); + use C4::Auth; + use C4::Output; + use C4::Context; + + my $query = CGI->new; + my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => 'errors/errorpage.tt', + query => $query, + type => 'intranet', + authnotrequired => 1, + debug => 1, + } + ); + $template->param ( + errno => 500, + admin => C4::Context->preference('KohaAdminEmailAddress'), + ); + my $output = $template->output; + my $length = length($output); + + return [ + 200, + ['Content-Type' => 'text/html; charset=UTF-8', 'Content-Length' => $length], + [$output] + ]; + }; + }; -- 2.20.1