Repository: deis/deis

Issue:
fix(client): json debugging error
Seeing this pop up recently in my client. I have a feeling it has something to do with some of the error catching code in `_dispatch`:

```
><> deis destroy --app dainty-vineyard

 !    WARNING: Potentially Destructive Action
 !    This command will destroy the application: dainty-vineyard
 !    To proceed, type "dainty-vineyard" or re-run this command with --confirm=dainty-vineyard

> dainty-vineyard
Destroying dainty-vineyard... Traceback (most recent call last):
  File "/Users/bacongobbler/bin/deis", line 1882, in <module>
    main()
  File "/Users/bacongobbler/bin/deis", line 1878, in main
    _dispatch_cmd(method, args)
  File "/Users/bacongobbler/bin/deis", line 1832, in _dispatch_cmd
    method(args)
  File "/Users/bacongobbler/bin/deis", line 504, in apps_destroy
    response = self._dispatch('delete', "/api/apps/{}".format(app))
  File "/Users/bacongobbler/bin/deis", line 381, in _dispatch
    if response.json().get('error') is not None:
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 741, in json
    return json.loads(self.text, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/simplejson/__init__.py", line 488, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python2.7/site-packages/simplejson/decoder.py", line 389, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
```



Discussion:
Note that the code was introduced by me, so I'll check through the history to see the justification behind this change.

I'm seeing something similar quite often now with the current CLI:

``` python
(venv)Rhialto:tests matt$ ../client/deis.py destroy -a testing --confirm=testing
Destroying testing... Traceback (most recent call last):
  File "../client/deis.py", line 1886, in <module>
    main()
  File "../client/deis.py", line 1882, in main
    _dispatch_cmd(method, args)
  File "../client/deis.py", line 1836, in _dispatch_cmd
    method(args)
  File "../client/deis.py", line 504, in apps_destroy
    response = self._dispatch('delete', "/api/apps/{}".format(app))
  File "../client/deis.py", line 381, in _dispatch
    if response.json().get('error') is not None:
  File "/Users/matt/Projects/src/github.com/deis/deis/client/venv/lib/python2.7/site-packages/requests/models.py", line 763, in json
    return json.loads(self.text, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode
    raise ValueError("No JSON object could be decoded")
```

https://github.com/deis/deis/commit/f9d47e3f77cf93ed28ef3d135804be47ab609525 is the commit to blame here


Resolving patch:
diff --git a/client/deis.py b/client/deis.py
--- a/client/deis.py
+++ b/client/deis.py
@@ -377,10 +377,6 @@ def _dispatch(self, method, path, body=None, **kwargs):
                 'No active controller. Use `deis login` or `deis register` to get started.')
         url = urlparse.urljoin(controller, path, **kwargs)
         response = func(url, data=body, headers=headers)
-        # check for errors
-        if response.json().get('error') is not None:
-            print(response.json()['error'])
-            sys.exit(1)
         return response
 
     def apps(self, args):
diff --git a/controller/api/middleware.py b/controller/api/middleware.py
--- a/controller/api/middleware.py
+++ b/controller/api/middleware.py
@@ -15,8 +15,8 @@ def process_request(self, request):
             server_version = __version__.rsplit('.', 1)[0]
             if client_version != server_version:
                 message = {
-                    'error': 'Client and server versions do not match.\n' +
-                    'Client version: {}\n'.format(client_version) +
+                    'error': 'Client and server versions do not match. ' +
+                    'Client version: {} '.format(client_version) +
                     'Server version: {}'.format(server_version)
                 }
                 return HttpResponse(


Test patch: