Skip to content
Snippets Groups Projects
Commit 866cc881 authored by Robert Lange's avatar Robert Lange Committed by Dorian Merz
Browse files

refs #15664 [master] set specific error messages for timeouts

* add finc bootstrapper with error listener
* add finc error templates for timeout and runtime
* add translations for timeout and service unavailable
* name Templates like Exception class name
* fix error message: use system email
* use vufind5 coding styles
parent f7cfbf27
No related merge requests found
......@@ -710,6 +710,8 @@ email_selected_favorites = "Ausgewählte Favoriten per E-Mail versenden"
email_sending = "Nachricht wird gesendet..."
email_success = "Nachricht versendet"
error_inconsistent_parameters = "Leider ist ein Fehler aufgetreten. Es wurden widersprüchliche Angaben entdeckt."
error_timeout = "Ihre Abfrage dauerte zu lange und wurde abgebrochen. Bitte versuchen Sie, die Seite neu zu laden oder stellen Sie eine einfachere Abfrage. Falls Ihre Abfrage bereits einfach war, schicken Sie uns bitte eine Nachricht mit der Abfrage (und ggf. URL) an <a href="%s">%s</a>, damit wir das Problem lösen können."
error_service_unavailable = "Die Suche ist vorübergehend nicht verfügbar. Bitte versuchen Sie es später noch einmal."
errorcode_error = "Es ist ein Fehler aufgetreten"
errorcode_http_status_error = "Kein Netzwerk vorhanden"
errorcode_empty_response_error = "Keine Nachricht vom Lokalsystem erhalten"
......
......@@ -698,6 +698,8 @@ email_selected_favorites = "E-mail Selected Favorites"
email_sending = "Sending Message..."
email_success = "Message Sent"
error_inconsistent_parameters = "Sorry, an error has occurred. Inconsistent parameters detected"
error_timeout = "Your query was taking too long and has been canceled. Please try to reload the page or make a simpler query. If your query was already simple, please send us a message with the query (if possible add URL) to <a href="mailto:%s">%s</a>, so that we can solve the problem."
error_service_unavailable = "Sorry, Service Is Temporarily Unavailable. Please retry again later."
errorcode_error = "Sorry, an error has occurred. Please try it again"
errorcode_http_status_error = "No network available for the Integrated Library System"
errorcode_empty_response_error = "No response received from the Integrated Library System"
......
......@@ -85,9 +85,10 @@ class Module
* @param MvcEvent $e Event
*
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function onBootstrap(MvcEvent $e)
{
$bootstrapper = new Bootstrapper($e);
$bootstrapper->bootstrap();
}
}
<?php
/**
* VuFind Bootstrapper
*
* PHP version 7
*
* Copyright (C) Leipzig University Library 2020.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Bootstrap
* @author Robert Lange <lange@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/
namespace finc;
use Zend\Console\Console;
/**
* Finc Bootstrapper
*
* @category VuFind
* @package Bootstrap
* @author Robert Lange <lange@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/
class Bootstrapper extends \VuFind\Bootstrapper
{
/**
* Bootstrap finc resources.
*
* @return void
*/
public function bootstrap()
{
// automatically call all methods starting with "init":
$methods = get_class_methods($this);
foreach ($methods as $method) {
if (substr($method, 0, 8) == 'initFinc') {
$this->$method();
}
}
}
/**
* Set up custom error page based on exception information.
*
* @return void
*/
protected function initFincCustomErrorView()
{
//custom error page not needed in console mode:
if (\Zend\Console\Console::isConsole()) {
return;
}
$callback = function ($e) {
$exception = $e->getParam('exception');
if (!$exception) {
return;
}
$exceptionName = end(
explode('\\', get_class($e->getParam('exception')))
);
$resolver = $e->getApplication()
->getServiceManager()->get('Zend\View\Resolver\TemplatePathStack');
if (false === $resolver->resolve($template = "error/$exceptionName")) {
// custom error template does not exist
return;
}
$model = new \Zend\View\Model\ViewModel(
[
'display_exceptions' => APPLICATION_ENV == 'development',
'exception' => $e->getParam('exception'),
]
);
$model->setTemplate($template);
$e->setResult($model);
};
$this->events->attach('dispatch.error', $callback);
}
}
<!-- finc: RuntimeException -->
<?/* largely copied from /bootstrap3/templates/error/index.phtml #17035 - RL */?>
<?php
// Set page title.
$this->headTitle($this->translate('An error has occurred'));
$this->layout()->breadcrumbs = '<li class="active">Error</li>';
?>
<div class="alert alert-danger">
<p><?=$this->transEsc('An error has occurred')?></p>
<p>
<?php if (strpos($exception->getMessage(), "nable to connect to") !== false): ?>
<?=$this->translate('error_service_unavailable')?>
<?php else: ?>
<p><?=$this->transEsc($this->message)?></p>
<?=$this->transEsc('Please contact the Library Reference Department for assistance')?>
<?php $supportEmail = $this->escapeHtmlAttr($this->systememail()); ?>
<a href="mailto:<?=$supportEmail?>"><?=$supportEmail?></a>
<?php endif; ?>
<br/>
</p>
</div>
<?php if ($this->showInstallLink): ?>
<h2><a href="<?=$this->url('install-home')?>"><?=$this->transEsc('auto_configure_title', [], 'Auto Configure')?></a></h2>
<?=$this->transEsc('auto_configure_description', [], 'If this is a new installation, you may be able to fix the error using VuFind\'s Auto Configure tool.')?>
<h2><a href="<?=$this->url('upgrade-home')?>"><?=$this->transEsc('Upgrade VuFind')?></a></h2>
<?=$this->transEsc('upgrade_description', [], 'If you are upgrading a previous VuFind version, you can load your old settings with this tool.')?>
<?php endif; ?>
<?php if (isset($this->display_exceptions) && $this->display_exceptions): ?>
<h2><?=$this->transEsc('Exception')?>:</h2>
<p>
<b><?=$this->transEsc('Message')?>:</b> <?=$this->escapeHtml($this->exception->getMessage())?>
</p>
<h2><?=$this->transEsc('Backtrace')?>:</h2>
<pre><?=$this->exception->getTraceAsString()?>
</pre>
<?php if ($e = $this->exception->getPrevious()): ?>
<h3>Previous exceptions:</h3>
<?php while ($e): ?>
<h4><?php echo get_class($e); ?></h4>
<p><?=$e->getMessage()?></p>
<pre><?=$e->getTraceAsString()?></pre>
<?php $e = $e->getPrevious(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php if (isset($this->request)): ?>
<h2><?=$this->transEsc('error_page_parameter_list_heading')?>:</h2>
<pre><?=$this->escapeHtml(var_export($this->request->getParams(), true))?></pre>
<?php endif; ?>
<?php endif ?>
<!-- finc: RuntimeException - END -->
<!-- finc: TimeoutException -->
<?/* largely copied from /bootstrap3/templates/error/index.phtml #17035 - RL */?>
<?php
// Set page title.
$this->headTitle($this->translate('An error has occurred'));
$this->layout()->breadcrumbs = '<li class="active">Error</li>';
?>
<div class="alert alert-danger">
<p>
<?=sprintf($this->translate('error_timeout'), $this->systememail(), $this->systememail())?>
<br/>
</p>
</div>
<?php if ($this->showInstallLink): ?>
<h2><a href="<?=$this->url('install-home')?>"><?=$this->transEsc('auto_configure_title', [], 'Auto Configure')?></a></h2>
<?=$this->transEsc('auto_configure_description', [], 'If this is a new installation, you may be able to fix the error using VuFind\'s Auto Configure tool.')?>
<h2><a href="<?=$this->url('upgrade-home')?>"><?=$this->transEsc('Upgrade VuFind')?></a></h2>
<?=$this->transEsc('upgrade_description', [], 'If you are upgrading a previous VuFind version, you can load your old settings with this tool.')?>
<?php endif; ?>
<?php if (isset($this->display_exceptions) && $this->display_exceptions): ?>
<h2><?=$this->transEsc('Exception')?>:</h2>
<p>
<b><?=$this->transEsc('Message')?>:</b> <?=$this->escapeHtml($this->exception->getMessage())?>
</p>
<h2><?=$this->transEsc('Backtrace')?>:</h2>
<pre><?=$this->exception->getTraceAsString()?>
</pre>
<?php if ($e = $this->exception->getPrevious()): ?>
<h3>Previous exceptions:</h3>
<?php while ($e): ?>
<h4><?php echo get_class($e); ?></h4>
<p><?=$e->getMessage()?></p>
<pre><?= $e->getTraceAsString()?></pre>
<?php $e = $e->getPrevious(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php if (isset($this->request)): ?>
<h2><?=$this->transEsc('error_page_parameter_list_heading')?>:</h2>
<pre><?=$this->escapeHtml(var_export($this->request->getParams(), true))?></pre>
<?php endif; ?>
<?php endif ?>
<!-- finc: TimeoutException - END -->
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment