@@ -38,7 +38,8 @@ def get_object(self):
3838 def passwd (self , request , ** kwargs ):
3939 obj = self .get_object ()
4040 if not obj .check_password (request .DATA ['password' ]):
41- return Response ("Current password did not match" , status = status .HTTP_400_BAD_REQUEST )
41+ return Response ({'detail' : 'Current password does not match' },
42+ status = status .HTTP_400_BAD_REQUEST )
4243 obj .set_password (request .DATA ['new_password' ])
4344 obj .save ()
4445 return Response ({'status' : 'password set' })
@@ -60,7 +61,7 @@ def create(self, request, *args, **kwargs):
6061 return super (BaseDeisViewSet , self ).create (request , * args , ** kwargs )
6162 # If the scheduler oopsie'd
6263 except RuntimeError as e :
63- return Response (str (e ), status = status .HTTP_503_SERVICE_UNAVAILABLE )
64+ return Response ({ 'detail' : str (e )} , status = status .HTTP_503_SERVICE_UNAVAILABLE )
6465
6566
6667class AppResourceViewSet (BaseDeisViewSet ):
@@ -131,22 +132,20 @@ def post_save(self, app):
131132
132133 def scale (self , request , ** kwargs ):
133134 new_structure = {}
135+ app = self .get_object ()
134136 try :
135137 for target , count in request .DATA .items ():
136138 new_structure [target ] = int (count )
137- except (TypeError , ValueError ):
138- return Response ('Invalid scaling format' ,
139- status = status .HTTP_400_BAD_REQUEST )
140- app = self .get_object ()
141- try :
142139 models .validate_app_structure (new_structure )
143140 app .scale (request .user , new_structure )
144- except (EnvironmentError , ValidationError ) as e :
145- return Response (str (e ), status = status .HTTP_400_BAD_REQUEST )
141+ except (TypeError , ValueError ):
142+ return Response ({'detail' : 'Invalid scaling format' },
143+ status = status .HTTP_400_BAD_REQUEST )
144+ except (ValidationError , EnvironmentError ) as e :
145+ return Response ({'detail' : str (e )}, status = status .HTTP_400_BAD_REQUEST )
146146 except RuntimeError as e :
147- return Response (str (e ), status = status .HTTP_503_SERVICE_UNAVAILABLE )
148- return Response (status = status .HTTP_204_NO_CONTENT ,
149- content_type = 'application/json' )
147+ return Response ({'detail' : str (e )}, status = status .HTTP_503_SERVICE_UNAVAILABLE )
148+ return Response (status = status .HTTP_204_NO_CONTENT )
150149
151150 def logs (self , request , ** kwargs ):
152151 app = self .get_object ()
@@ -165,9 +164,9 @@ def run(self, request, **kwargs):
165164 try :
166165 output_and_rc = app .run (self .request .user , command )
167166 except EnvironmentError as e :
168- return Response (str (e ), status = status .HTTP_400_BAD_REQUEST )
167+ return Response ({ 'detail' : str (e )} , status = status .HTTP_400_BAD_REQUEST )
169168 except RuntimeError as e :
170- return Response (str (e ), status = status .HTTP_503_SERVICE_UNAVAILABLE )
169+ return Response ({ 'detail' : str (e )} , status = status .HTTP_503_SERVICE_UNAVAILABLE )
171170 return Response (output_and_rc , status = status .HTTP_200_OK ,
172171 content_type = 'text/plain' )
173172
@@ -252,7 +251,7 @@ def rollback(self, request, **kwargs):
252251 response = {'version' : new_release .version }
253252 return Response (response , status = status .HTTP_201_CREATED )
254253 except EnvironmentError as e :
255- return Response (str (e ), status = status .HTTP_400_BAD_REQUEST )
254+ return Response ({ 'detail' : str (e )} , status = status .HTTP_400_BAD_REQUEST )
256255 except RuntimeError :
257256 new_release .delete ()
258257 raise
0 commit comments