Simplify exception handling
This commit is contained in:
parent
6b6458f2ea
commit
6f82f19049
|
@ -1,16 +1,12 @@
|
||||||
import requests
|
import requests
|
||||||
from requests.exceptions import HTTPError
|
from requests.exceptions import RequestException
|
||||||
from requests.exceptions import InvalidURL
|
|
||||||
|
|
||||||
import httplib
|
|
||||||
import datetime
|
import datetime
|
||||||
import socket
|
|
||||||
from urllib3.contrib import pyopenssl
|
from urllib3.contrib import pyopenssl
|
||||||
|
|
||||||
from ckan import model
|
from ckan import model
|
||||||
from ckan.logic import ValidationError, NotFound, get_action
|
from ckan.logic import ValidationError, NotFound, get_action
|
||||||
from ckan.lib.helpers import json
|
from ckan.lib.helpers import json
|
||||||
from ckan.lib.munge import munge_name
|
|
||||||
from ckan.plugins import toolkit
|
from ckan.plugins import toolkit
|
||||||
|
|
||||||
from ckanext.harvest.model import HarvestObject
|
from ckanext.harvest.model import HarvestObject
|
||||||
|
@ -46,17 +42,8 @@ class CKANHarvester(HarvesterBase):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
http_request = requests.get(url, headers=headers)
|
http_request = requests.get(url, headers=headers)
|
||||||
except HTTPError as e:
|
except RequestException as e:
|
||||||
if e.response.status_code == 404:
|
raise ContentFetchError('HTTP error: %s' % e.code)
|
||||||
raise ContentNotFoundError('HTTP error: %s' % e.code)
|
|
||||||
else:
|
|
||||||
raise ContentFetchError('HTTP error: %s' % e.code)
|
|
||||||
except InvalidURL as e:
|
|
||||||
raise ContentFetchError('URL error: %s' % e.reason)
|
|
||||||
except httplib.HTTPException as e:
|
|
||||||
raise ContentFetchError('HTTP Exception: %s' % e)
|
|
||||||
except socket.error as e:
|
|
||||||
raise ContentFetchError('HTTP socket error: %s' % e)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ContentFetchError('HTTP general exception: %s' % e)
|
raise ContentFetchError('HTTP general exception: %s' % e)
|
||||||
return http_request.text
|
return http_request.text
|
||||||
|
|
Loading…
Reference in New Issue