Further clean up error handling
This commit is contained in:
parent
92fcc523c5
commit
58793d95d7
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user