Viewing file: errors.py (5.48 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2020 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT from clwpos import gettext as _ from clwpos.cl_wpos_exceptions import WposError
class WebsiteCheckError(WposError): """ Generic base class for all website post checks. """
def __init__(self, *, header, description, fix_tip, context, details=None): super(WebsiteCheckError, self).__init__( message=description, context=context ) self.header = header self.fix_tip = fix_tip self.details = details
class WebsiteCheckBadHttpCode(WebsiteCheckError): """ Happens when we get unexpected status code from website. Usually user must go check logs and fix this issue himself. """ HEADER = _('Bad http status code response') MESSAGE_TEMPLATE = _( 'Unsuccessful attempt to request website main page: ' '<a href="%(url)s" target="_blank">%(url)s</a>. ' 'Webserver responded with http status code %(http_code)s.')
FIX_TIP = _( 'Search your webserver logs for errors and manually ' 'check that WordPress site is working properly.' )
def __init__(self, url, http_code): super(WebsiteCheckBadHttpCode, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( url=url, http_code=http_code ), fix_tip=self.FIX_TIP )
class WebsiteTimeout(WebsiteCheckError): """ Happens when website does not respond in hardcoded timeout. """ HEADER = _('Response timeout reached') MESSAGE_TEMPLATE = _( 'Unsuccessful attempt to request website main page: ' '<a href="%(url)s" target="_blank">%(url)s</a>. ' 'Webserver responds longer than %(timeout)s seconds ' '(most likely it is not working).')
FIX_TIP = _( 'Make sure that WordPress site is working properly and ' 'specified url gives response in %(timeout)s seconds. ' 'Search your webserver logs for errors that may cause the timeout issue.' )
def __init__(self, url, timeout): super(WebsiteTimeout, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( url=url, timeout=timeout ), fix_tip=self.FIX_TIP )
class WebsiteHttpsBroken(WebsiteCheckError): """ Happens when website has invalid or outdated https certificate. """ HEADER = _('Broken https certificate') MESSAGE_TEMPLATE = _( 'Unsuccessful attempt to request website main page: ' '<a href="%(url)s" target="_blank">%(url)s</a>. ' 'Webserver redirected http request to https, but the last ' 'one does not have a valid certificate.')
FIX_TIP = _( 'Make sure that https certificate is valid and up to date or ' 'disable http to https redirection in your control panel.' )
def __init__(self, url, details): super(WebsiteHttpsBroken, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( url=url ), fix_tip=self.FIX_TIP, details=details )
class WebsiteNotResponding(WebsiteCheckError): """ Happens when website does not have working webserver at all. """ HEADER = _('Website it not responding') MESSAGE_TEMPLATE = _( 'Unsuccessful attempt to request website main page: ' '<a href="%(url)s" target="_blank">%(url)s</a>. ' 'Webserver did not return any response.')
FIX_TIP = _( 'Make sure that webserver is working and your website is accessible: ' 'you can use `curl %(url)s` to check response.' )
def __init__(self, url, details): super(WebsiteNotResponding, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( url=url ), fix_tip=self.FIX_TIP, details=details )
class RollbackException(WposError):
MESSAGE_TEMPLATE = _( "Action failed and rolled back. Here is why." )
def __init__(self, *reasons: WebsiteCheckError): self.errors = [ dict( header=reason.header, description=reason.message, fix_tip=reason.fix_tip, type='post_check', context=reason.context, details=reason.details ) for reason in reasons ] super(RollbackException, self).__init__(message='rollback')
class PhpLogErrorsFound(WebsiteCheckError): HEADER = _('Website server error') MESSAGE_TEMPLATE = _( 'We found some errors in the website log file: %(error_log_path)s. ' 'Here is some context: \n' '%(log_record)s')
FIX_TIP = _( 'Check found errors and decide whether they are critical or not. ' 'Contact your system administrator for help if needed.' )
def __init__(self, error_log_path, log_record): super(PhpLogErrorsFound, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( error_log_path=error_log_path, log_record=log_record ), fix_tip=self.FIX_TIP )
|