Add exception handling for the API version parsing

I have added try-except clauses in order to prevent the process from
crashing if a non-parsable integer is used for the api_version option.

Signed-off-by: Konrad Reiche <konrad.reiche@fokus.fraunhofer.de>
This commit is contained in:
Konrad Reiche 2013-05-27 13:12:05 +02:00
parent 05094090af
commit c858b9fe9f
2 changed files with 9 additions and 2 deletions

View File

@ -130,7 +130,11 @@ class HarvesterBase(SingletonPlugin):
# Check API version
if self.config:
api_version = int(self.config.get('api_version', 2))
try:
api_version = int(self.config.get('api_version', 2))
except ValueError:
raise ValueError('api_version must be an integer')
#TODO: use site user when available
user_name = self.config.get('user', u'harvest')
else:

View File

@ -53,7 +53,10 @@ class CKANHarvester(HarvesterBase):
self.config = json.loads(config_str)
if 'api_version' in self.config:
self.api_version = int(self.config['api_version'])
try:
self.api_version = int(self.config['api_version'])
except ValueError:
raise ValueError('api_version must be an integer')
log.debug('Using config: %r', self.config)
else: