2020-12-12 10:23:17 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
|
|
|
|
# Copyright (C) 2018-2020 OzzieIsaacs
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import traceback
|
2022-04-26 09:28:20 +00:00
|
|
|
|
2020-12-12 10:23:17 +00:00
|
|
|
from flask import render_template
|
|
|
|
from werkzeug.exceptions import default_exceptions
|
|
|
|
try:
|
|
|
|
from werkzeug.exceptions import FailedDependency
|
|
|
|
except ImportError:
|
|
|
|
from werkzeug.exceptions import UnprocessableEntity as FailedDependency
|
|
|
|
|
|
|
|
from . import config, app, logger, services
|
|
|
|
|
|
|
|
|
|
|
|
log = logger.create()
|
|
|
|
|
|
|
|
# custom error page
|
2024-06-18 18:13:26 +00:00
|
|
|
|
2020-12-12 10:23:17 +00:00
|
|
|
def error_http(error):
|
|
|
|
return render_template('http_error.html',
|
|
|
|
error_code="Error {0}".format(error.code),
|
|
|
|
error_name=error.name,
|
|
|
|
issue=False,
|
2021-05-28 11:56:07 +00:00
|
|
|
unconfigured=not config.db_configured,
|
2020-12-12 10:23:17 +00:00
|
|
|
instance=config.config_calibre_web_title
|
|
|
|
), error.code
|
|
|
|
|
|
|
|
|
|
|
|
def internal_error(error):
|
|
|
|
return render_template('http_error.html',
|
2022-04-03 18:26:43 +00:00
|
|
|
error_code="500 Internal Server Error",
|
|
|
|
error_name='The server encountered an internal error and was unable to complete your '
|
|
|
|
'request. There is an error in the application.',
|
2020-12-12 10:23:17 +00:00
|
|
|
issue=True,
|
2021-05-28 11:56:07 +00:00
|
|
|
unconfigured=False,
|
2020-12-12 10:23:17 +00:00
|
|
|
error_stack=traceback.format_exc().split("\n"),
|
|
|
|
instance=config.config_calibre_web_title
|
|
|
|
), 500
|
|
|
|
|
2024-06-18 18:13:26 +00:00
|
|
|
|
2020-12-12 14:16:22 +00:00
|
|
|
def init_errorhandler():
|
|
|
|
# http error handling
|
|
|
|
for ex in default_exceptions:
|
|
|
|
if ex < 500:
|
|
|
|
app.register_error_handler(ex, error_http)
|
|
|
|
elif ex == 500:
|
|
|
|
app.register_error_handler(ex, internal_error)
|
2020-12-12 10:23:17 +00:00
|
|
|
|
2020-12-12 14:16:22 +00:00
|
|
|
if services.ldap:
|
|
|
|
# Only way of catching the LDAPException upon logging in with LDAP server down
|
|
|
|
@app.errorhandler(services.ldap.LDAPException)
|
2021-03-15 12:48:05 +00:00
|
|
|
# pylint: disable=unused-variable
|
2020-12-12 14:16:22 +00:00
|
|
|
def handle_exception(e):
|
|
|
|
log.debug('LDAP server not accessible while trying to login to opds feed')
|
|
|
|
return error_http(FailedDependency())
|
2020-12-12 10:23:17 +00:00
|
|
|
|