Move QuteSchemeError to qutescheme

This commit is contained in:
Florian Bruhin 2016-09-14 11:04:37 +02:00
parent aa71c9ae58
commit 71bc5bb943
2 changed files with 22 additions and 3 deletions

View File

@ -56,6 +56,24 @@ def add_handler(name):
"""Add a handler to the qute: scheme."""
def namedecorator(function):
_HANDLERS[name] = function
class QuteSchemeError(Exception):
"""Exception to signal that a handler should return an ErrorReply.
Attributes correspond to the arguments in
networkreply.ErrorNetworkReply.
Attributes:
errorstring: Error string to print.
error: Numerical error value.
"""
def __init__(self, errorstring, error):
self.errorstring = errorstring
self.error = error
super().__init__(errorstring)
return function
return namedecorator

View File

@ -76,7 +76,7 @@ class QuteSchemeHandler(schemehandler.SchemeHandler):
return networkreply.ErrorNetworkReply(
request, str(e), QNetworkReply.ContentNotFoundError,
self.parent())
except QuteSchemeError as e:
except qutescheme.QuteSchemeError as e:
return networkreply.ErrorNetworkReply(request, e.errorstring,
e.error, self.parent())
@ -123,5 +123,6 @@ def qute_pdfjs(url):
# information, as the failed pdfjs requests are still in the log.
log.misc.warning(
"pdfjs resource requested but not found: {}".format(e.path))
raise QuteSchemeError("Can't find pdfjs resource '{}'".format(e.path),
QNetworkReply.ContentNotFoundError)
raise qutescheme.QuteSchemeError("Can't find pdfjs resource "
"'{}'".format(e.path),
QNetworkReply.ContentNotFoundError)