@@ -362,18 +362,25 @@ def __init__(self):
362362 self ._session = Session ()
363363 self ._settings = Settings ()
364364
365- def _dispatch (self , method , path , body = None ,
366- headers = {'content-type' : 'application/json' }, ** kwargs ):
365+ def _dispatch (self , method , path , body = None , ** kwargs ):
367366 """
368367 Dispatch an API request to the active Deis controller
369368 """
369+ headers = {
370+ 'content-type' : 'application/json' ,
371+ 'X-Deis-Version' : __version__ .rsplit ('.' , 1 )[0 ],
372+ }
370373 func = getattr (self ._session , method .lower ())
371374 controller = self ._settings ['controller' ]
372375 if not controller :
373376 raise EnvironmentError (
374377 'No active controller. Use `deis login` or `deis register` to get started.' )
375378 url = urlparse .urljoin (controller , path , ** kwargs )
376379 response = func (url , data = body , headers = headers )
380+ # check for errors
381+ if response .json ().get ('error' ) is not None :
382+ print (response .json ()['error' ])
383+ sys .exit (1 )
377384 return response
378385
379386 def apps (self , args ):
@@ -1605,7 +1612,7 @@ def main():
16051612 call the appropriate method on the client.
16061613 """
16071614 cli = DeisClient ()
1608- args = docopt (__doc__ , version = 'Deis CLI {}' . format ( __version__ ) ,
1615+ args = docopt (__doc__ , version = __version__ ,
16091616 options_first = True )
16101617 cmd = args ['<command>' ]
16111618 cmd , help_flag = parse_args (cmd )
0 commit comments