1818
1919from api import authentication , models , permissions , serializers , viewsets
2020from api .models import AlreadyExists
21+ from scheduler import KubeException
2122
2223import requests
2324import logging
@@ -152,7 +153,7 @@ def create(self, request, *args, **kwargs):
152153 try :
153154 return super (BaseDeisViewSet , self ).create (request , * args , ** kwargs )
154155 # If the scheduler oopsie'd
155- except RuntimeError as e :
156+ except KubeException as e :
156157 return Response ({'detail' : str (e )}, status = status .HTTP_503_SERVICE_UNAVAILABLE )
157158
158159
@@ -230,7 +231,7 @@ def scale(self, request, **kwargs):
230231 status = status .HTTP_400_BAD_REQUEST )
231232 except (EnvironmentError , ValidationError ) as e :
232233 return Response ({'detail' : str (e )}, status = status .HTTP_400_BAD_REQUEST )
233- except RuntimeError as e :
234+ except KubeException as e :
234235 return Response ({'detail' : str (e )}, status = status .HTTP_503_SERVICE_UNAVAILABLE )
235236 return Response (status = status .HTTP_204_NO_CONTENT )
236237
@@ -260,7 +261,7 @@ def run(self, request, **kwargs):
260261 rc , output = app .run (self .request .user , request .data ['command' ])
261262 except EnvironmentError as e :
262263 return Response ({'detail' : str (e )}, status = status .HTTP_400_BAD_REQUEST )
263- except RuntimeError as e :
264+ except KubeException as e :
264265 return Response ({'detail' : str (e )}, status = status .HTTP_503_SERVICE_UNAVAILABLE )
265266 return Response ({'rc' : rc , 'output' : str (output )})
266267
@@ -322,7 +323,7 @@ def list(self, *args, **kwargs):
322323 # fake out pagination for now
323324 pagination = {'results' : data , 'count' : len (data )}
324325 return Response (pagination , status = status .HTTP_200_OK )
325- except Exception as e :
326+ except KubeException as e :
326327 return Response ({'detail' : str (e )}, status = status .HTTP_503_SERVICE_UNAVAILABLE )
327328
328329 def restart (self , * args , ** kwargs ):
@@ -335,7 +336,7 @@ def restart(self, *args, **kwargs):
335336 # pagination = {'results': data, 'count': len(data)}
336337 pagination = data
337338 return Response (pagination , status = status .HTTP_200_OK )
338- except Exception as e :
339+ except KubeException as e :
339340 return Response ({'detail' : str (e )}, status = status .HTTP_503_SERVICE_UNAVAILABLE )
340341
341342
@@ -368,7 +369,7 @@ def attach(self, request, *args, **kwargs):
368369 raise
369370 except AlreadyExists as e :
370371 return Response ({'detail' : str (e )}, status = status .HTTP_409_CONFLICT )
371- except Exception as e :
372+ except KubeException as e :
372373 return Response ({'detail' : str (e )}, status = status .HTTP_503_SERVICE_UNAVAILABLE )
373374
374375 return Response (status = status .HTTP_201_CREATED )
@@ -378,7 +379,7 @@ def detach(self, request, *args, **kwargs):
378379 self .get_object ().detach (* args , ** kwargs )
379380 except Http404 :
380381 raise
381- except Exception as e :
382+ except KubeException as e :
382383 return Response ({'detail' : str (e )}, status = status .HTTP_503_SERVICE_UNAVAILABLE )
383384
384385 return Response (status = status .HTTP_204_NO_CONTENT )
@@ -417,7 +418,7 @@ def rollback(self, request, **kwargs):
417418 return Response (response , status = status .HTTP_201_CREATED )
418419 except EnvironmentError as e :
419420 return Response ({'detail' : str (e )}, status = status .HTTP_400_BAD_REQUEST )
420- except RuntimeError :
421+ except Exception :
421422 if 'new_release' in locals ():
422423 new_release .delete ()
423424 raise
0 commit comments