summaryrefslogtreecommitdiff
path: root/searx/exceptions.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2017-01-20 18:52:47 +0100
committerAlexandre Flament <alex@al-f.net>2017-01-20 18:52:47 +0100
commit15eef0ebdb15af80c026302bef250dc7f4417951 (patch)
treec1e5ab56359ed3f23a17e6721cae1c4fbf6d88af /searx/exceptions.py
parent7fdfeca3a43e0e2bd8ef2dcb27cca7745edf596a (diff)
downloadsearxng-15eef0ebdb15af80c026302bef250dc7f4417951.tar.gz
searxng-15eef0ebdb15af80c026302bef250dc7f4417951.zip
[enh] validate input and raise an exception inside search.py. The exception message is output in json and rss format.
Diffstat (limited to 'searx/exceptions.py')
-rw-r--r--searx/exceptions.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/searx/exceptions.py b/searx/exceptions.py
new file mode 100644
index 000000000..c605ddcab
--- /dev/null
+++ b/searx/exceptions.py
@@ -0,0 +1,32 @@
+'''
+searx is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+searx 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 Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with searx. If not, see < http://www.gnu.org/licenses/ >.
+
+(C) 2017- by Alexandre Flament, <alex@al-f.net>
+'''
+
+
+class SearxException(Exception):
+ pass
+
+
+class SearxParameterException(SearxException):
+
+ def __init__(self, name, value):
+ if value == '' or value is None:
+ message = 'Empty ' + name + ' parameter'
+ else:
+ message = 'Invalid value "' + value + '" for parameter ' + name
+ super(SearxParameterException, self).__init__(message)
+ self.parameter_name = name
+ self.parameter_value = value