Further clean up error handling

This commit is contained in:
Florian Bruhin 2018-07-10 01:17:19 +02:00 committed by Florian Bruhin
parent 92fcc523c5
commit 58793d95d7
3 changed files with 34 additions and 30 deletions

View File

@ -80,21 +80,23 @@ class QuteSchemeHandler(QWebEngineUrlSchemeHandler):
log.misc.debug("Got request for {}".format(url.toDisplayString()))
try:
mimetype, data = qutescheme.data_for_url(url)
except qutescheme.NotFoundError:
log.misc.exception("Error while handling qute://* URL")
job.fail(QWebEngineUrlRequestJob.UrlNotFound)
except qutescheme.UrlInvalidError:
log.misc.exception("Error while handling qute://* URL")
job.fail(QWebEngineUrlRequestJob.UrlInvalid)
except qutescheme.RequestDeniedError:
log.misc.exception("Error while handling qute://* URL")
job.fail(QWebEngineUrlRequestJob.RequestDenied)
except qutescheme.SchemeOSError:
log.misc.exception("OSError while handling qute://* URL")
job.fail(QWebEngineUrlRequestJob.UrlNotFound)
except qutescheme.Error:
log.misc.exception("Error while handling qute://* URL")
job.fail(QWebEngineUrlRequestJob.RequestFailed)
except qutescheme.Error as e:
errors = {
qutescheme.NotFoundError:
QWebEngineUrlRequestJob.UrlNotFound,
qutescheme.UrlInvalidError:
QWebEngineUrlRequestJob.UrlInvalid,
qutescheme.RequestDeniedError:
QWebEngineUrlRequestJob.RequestDenied,
qutescheme.SchemeOSError:
QWebEngineUrlRequestJob.UrlNotFound,
qutescheme.Error:
QWebEngineUrlRequestJob.RequestFailed,
}
exctype = e.__type__
log.misc.exception("{} while handling qute://* URL".format(
exctype.__name__))
job.fail(errors[exctype])
except qutescheme.Redirect as e:
qtutils.ensure_valid(e.url)
job.redirect(e.url)

View File

@ -59,21 +59,23 @@ def handler(request, operation, current_url):
try:
mimetype, data = qutescheme.data_for_url(url)
except qutescheme.NotFoundError as e:
return networkreply.ErrorNetworkReply(
request, str(e), QNetworkReply.ContentNotFoundError)
except qutescheme.SchemeOSError as e:
return networkreply.ErrorNetworkReply(
request, str(e), QNetworkReply.ContentNotFoundError)
except qutescheme.UrlInvalidError as e:
return networkreply.ErrorNetworkReply(
request, str(e), QNetworkReply.ContentOperationNotPermittedError)
except qutescheme.RequestDeniedError as e:
return networkreply.ErrorNetworkReply(
request, str(e), QNetworkReply.ContentAccessDenied)
except qutescheme.Error as e:
return networkreply.ErrorNetworkReply(
request, str(e), QNetworkReply.InternalServerError)
errors = {
qutescheme.NotFoundError:
QNetworkReply.ContentNotFoundError,
qutescheme.UrlInvalidError:
QNetworkReply.ContentOperationNotPermittedError,
qutescheme.RequestDeniedError:
QNetworkReply.ContentAccessDenied,
qutescheme.SchemeOSError:
QNetworkReply.ContentNotFoundError,
qutescheme.Error:
QNetworkReply.InternalServerError,
}
exctype = e.__type__
log.misc.exception("{} while handling qute://* URL".format(
exctype.__name__))
return networkreply.ErrorNetworkReply(request, str(e), errors[exctype])
except qutescheme.Redirect as e:
qtutils.ensure_valid(e.url)
return networkreply.RedirectNetworkReply(e.url)

View File

@ -67,7 +67,7 @@ class TestJavascriptHandler:
def test_qutejavascript_empty_query(self):
url = QUrl("qute://javascript")
with pytest.raises(qutescheme.InvalidURLError):
with pytest.raises(qutescheme.UrlInvalidError):
qutescheme.qute_javascript(url)