22
22
#
23
23
24
24
import urllib .parse
25
+ from requests .exceptions import RequestException
25
26
from .webutil import get_uri
26
27
from .restful import do_api_call
27
28
@@ -42,7 +43,7 @@ def get_repos(logger, project, uri, headers=None, timeout=None):
42
43
urllib .parse .quote_plus (project ),
43
44
'repositories' ),
44
45
headers = headers , timeout = timeout )
45
- except Exception as exception :
46
+ except RequestException as exception :
46
47
logger .error ("could not get repositories for project '{}': {}" .
47
48
format (project , exception ))
48
49
return None
@@ -64,7 +65,7 @@ def get_config_value(logger, name, uri, headers=None, timeout=None):
64
65
res = do_api_call ('GET' , get_uri (uri , 'api' , 'v1' , 'configuration' ,
65
66
urllib .parse .quote_plus (name )),
66
67
headers = headers , timeout = timeout )
67
- except Exception as exception :
68
+ except RequestException as exception :
68
69
logger .error ("Cannot get the '{}' config value from the web "
69
70
"application: {}" .format (name , exception ))
70
71
return None
@@ -90,7 +91,7 @@ def set_config_value(logger, name, value, uri, headers=None, timeout=None):
90
91
local_headers ['Content-type' ] = 'application/text'
91
92
do_api_call ('PUT' , get_uri (uri , 'api' , 'v1' , 'configuration' , name ),
92
93
data = value , headers = local_headers , timeout = timeout )
93
- except Exception as exception :
94
+ except RequestException as exception :
94
95
logger .error ("Cannot set the '{}' config field to '{}' in the web "
95
96
"application: {}" .format (name , value , exception ))
96
97
return False
@@ -110,7 +111,7 @@ def get_repo_type(logger, repository, uri, headers=None, timeout=None):
110
111
res = do_api_call ('GET' , get_uri (uri , 'api' , 'v1' , 'repositories' ,
111
112
'property' , 'type' ), params = payload ,
112
113
headers = headers , timeout = timeout )
113
- except Exception as exception :
114
+ except RequestException as exception :
114
115
logger .error ("could not get repository type for '{}' from web"
115
116
"application: {}" .format (repository , exception ))
116
117
return None
@@ -125,7 +126,7 @@ def get_configuration(logger, uri, headers=None, timeout=None):
125
126
try :
126
127
res = do_api_call ('GET' , get_uri (uri , 'api' , 'v1' , 'configuration' ),
127
128
headers = headers , timeout = timeout )
128
- except Exception as exception :
129
+ except RequestException as exception :
129
130
logger .error ('could not get configuration from web application: {}' .
130
131
format (exception ))
131
132
return None
@@ -140,7 +141,7 @@ def set_configuration(logger, configuration, uri, headers=None, timeout=None, ap
140
141
if r is None or r .status_code != 201 :
141
142
logger .error ('could not set configuration to web application' )
142
143
return False
143
- except Exception as exception :
144
+ except RequestException as exception :
144
145
logger .error ('could not set configuration to web application: {}' .
145
146
format (exception ))
146
147
return False
@@ -153,7 +154,7 @@ def list_projects(logger, uri, headers=None, timeout=None):
153
154
res = do_api_call ('GET' ,
154
155
get_uri (uri , 'api' , 'v1' , 'projects' ),
155
156
headers = headers , timeout = timeout )
156
- except Exception as exception :
157
+ except RequestException as exception :
157
158
logger .error ("could not list projects from web application: {}" .
158
159
format (exception ))
159
160
return None
@@ -166,7 +167,7 @@ def list_indexed_projects(logger, uri, headers=None, timeout=None):
166
167
res = do_api_call ('GET' ,
167
168
get_uri (uri , 'api' , 'v1' , 'projects' , 'indexed' ),
168
169
headers = headers , timeout = timeout )
169
- except Exception as exception :
170
+ except RequestException as exception :
170
171
logger .error ("could not list indexed projects from web application: {}" .
171
172
format (exception ))
172
173
return None
@@ -181,7 +182,7 @@ def add_project(logger, project, uri, headers=None, timeout=None, api_timeout=No
181
182
if r is None or r .status_code != 201 :
182
183
logger .error (f"could not add project '{ project } ' in web application" )
183
184
return False
184
- except Exception as exception :
185
+ except RequestException as exception :
185
186
logger .error ("could not add project '{}' to web application: {}" .
186
187
format (project , exception ))
187
188
return False
@@ -197,7 +198,7 @@ def delete_project(logger, project, uri, headers=None, timeout=None, api_timeout
197
198
if r is None or r .status_code != 204 :
198
199
logger .error (f"could not delete project '{ project } ' in web application" )
199
200
return False
200
- except Exception as exception :
201
+ except RequestException as exception :
201
202
logger .error ("could not delete project '{}' in web application: {}" .
202
203
format (project , exception ))
203
204
return False
0 commit comments