Skip to content

Commit 01152da

Browse files
author
Gauvain Pocentek
committed
raise an exception on 401 return code
1 parent c4920ee commit 01152da

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

gitlab.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def list(self, objClass, **kwargs):
9696
for obj in l:
9797
obj.__dict__[k] = v
9898
return l
99+
elif r.status_code == 401:
100+
raise GitlabAuthenticationError(r.json['message'])
99101
else:
100102
raise GitlabGetError('%d: %s'%(r.status_code, r.text))
101103

@@ -120,6 +122,8 @@ def get(self, objClass, id, **kwargs):
120122
for k,v in kwargs.items():
121123
obj.__dict__[k] = v
122124
return obj
125+
elif r.status_code == 401:
126+
raise GitlabAuthenticationError(r.json['message'])
123127
else:
124128
raise GitlabGetError('%d: %s'%(r.status_code, r.text))
125129

@@ -137,6 +141,8 @@ def delete(self, objClass, id, **kwargs):
137141

138142
if r.status_code == 200:
139143
return True
144+
elif r.status_code == 401:
145+
raise GitlabAuthenticationError(r.json['message'])
140146
return False
141147

142148
def create(self, objClass, objData, **kwargs):
@@ -156,6 +162,8 @@ def create(self, objClass, objData, **kwargs):
156162
cls = objClass.returnClass
157163

158164
return cls(self, r.json)
165+
elif r.status_code == 401:
166+
raise GitlabAuthenticationError(r.json['message'])
159167
else:
160168
raise GitlabCreateError('%d: %s'%(r.status_code, r.text))
161169

@@ -176,6 +184,8 @@ def update(self, objClass, id, objData, **kwargs):
176184
cls = objClass.returnClass
177185

178186
return cls(self, r.json)
187+
elif r.status_code == 401:
188+
raise GitlabAuthenticationError(r.json['message'])
179189
else:
180190
raise GitlabUpdateError('%d: %s'%(r.status_code, r.text))
181191

0 commit comments

Comments
 (0)