@@ -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 ):
@@ -116,22 +117,20 @@ def post_save(self, app):
116117
117118 def scale (self , request , ** kwargs ):
118119 new_structure = {}
120+ app = self .get_object ()
119121 try :
120122 for target , count in request .DATA .items ():
121123 new_structure [target ] = int (count )
122- except (TypeError , ValueError ):
123- return Response ('Invalid scaling format' ,
124- status = status .HTTP_400_BAD_REQUEST )
125- app = self .get_object ()
126- try :
127124 models .validate_app_structure (new_structure )
128125 app .scale (request .user , new_structure )
129- except (EnvironmentError , ValidationError ) as e :
130- return Response (str (e ), status = status .HTTP_400_BAD_REQUEST )
126+ except (TypeError , ValueError ):
127+ return Response ({'detail' : 'Invalid scaling format' },
128+ status = status .HTTP_400_BAD_REQUEST )
129+ except (ValidationError , EnvironmentError ) as e :
130+ return Response ({'detail' : str (e )}, status = status .HTTP_400_BAD_REQUEST )
131131 except RuntimeError as e :
132- return Response (str (e ), status = status .HTTP_503_SERVICE_UNAVAILABLE )
133- return Response (status = status .HTTP_204_NO_CONTENT ,
134- content_type = 'application/json' )
132+ return Response ({'detail' : str (e )}, status = status .HTTP_503_SERVICE_UNAVAILABLE )
133+ return Response (status = status .HTTP_204_NO_CONTENT )
135134
136135 def logs (self , request , ** kwargs ):
137136 app = self .get_object ()
@@ -150,9 +149,9 @@ def run(self, request, **kwargs):
150149 try :
151150 output_and_rc = app .run (self .request .user , command )
152151 except EnvironmentError as e :
153- return Response (str (e ), status = status .HTTP_400_BAD_REQUEST )
152+ return Response ({ 'detail' : str (e )} , status = status .HTTP_400_BAD_REQUEST )
154153 except RuntimeError as e :
155- return Response (str (e ), status = status .HTTP_503_SERVICE_UNAVAILABLE )
154+ return Response ({ 'detail' : str (e )} , status = status .HTTP_503_SERVICE_UNAVAILABLE )
156155 return Response (output_and_rc , status = status .HTTP_200_OK ,
157156 content_type = 'text/plain' )
158157
@@ -237,7 +236,7 @@ def rollback(self, request, **kwargs):
237236 response = {'version' : new_release .version }
238237 return Response (response , status = status .HTTP_201_CREATED )
239238 except EnvironmentError as e :
240- return Response (str (e ), status = status .HTTP_400_BAD_REQUEST )
239+ return Response ({ 'detail' : str (e )} , status = status .HTTP_400_BAD_REQUEST )
241240 except RuntimeError :
242241 new_release .delete ()
243242 raise
0 commit comments