From a02102e40f887017ab4588f054fe06e77d44f446 Mon Sep 17 00:00:00 2001
From: Miles Wells <k1o0@3tk.co>
Date: Thu, 21 Oct 2021 19:12:32 +0300
Subject: [PATCH] more readable error message; raw JSON printed to debug logger

---
 CHANGELOG.md     |  7 ++++++-
 one/webclient.py | 18 ++++++++++--------
 setup.py         |  2 +-
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f582712..07eac69 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,10 @@
 # Changelog
+## [Latest](https://github.com/int-brain-lab/ONE/commits/main) [1.6.2]
+
+### Modified
+
+- more readable error message; raw JSON printed to debug logger
+
 ## [Latest](https://github.com/int-brain-lab/ONE/commits/main) [1.6.1]
 
 ### Modified
@@ -6,7 +12,6 @@
 - rest command loging includes the whole json field on error
 - added silent option to instantiate One on local files
 
-
 ## [1.6.0]
 
 ### Added
diff --git a/one/webclient.py b/one/webclient.py
index b6d7382..1d2a16c 100644
--- a/one/webclient.py
+++ b/one/webclient.py
@@ -542,8 +542,11 @@ class AlyxClient():
         elif r and r.status_code == 204:
             return
         else:
+            _logger.debug('Response text: ' + r.text)
             try:
                 message = json.loads(r.text)
+                message.pop('status_code', None)  # Get status code from response object instead
+                message = message.get('detail') or message  # Get details if available
             except json.decoder.JSONDecodeError:
                 message = r.text
             raise requests.HTTPError(r.status_code, rest_query, message, response=r)
@@ -790,7 +793,6 @@ class AlyxClient():
         JSON interpreted dictionary from response
         """
         rep = self._generic_request(requests.get, rest_query, **kwargs)
-        _logger.debug(rest_query)
         if isinstance(rep, dict) and list(rep.keys()) == ['count', 'next', 'previous', 'results']:
             if len(rep['results']) < rep['count']:
                 cache_args = {k: v for k, v in kwargs.items() if k in ('clobber', 'expires')}
@@ -998,8 +1000,8 @@ class AlyxClient():
             field_name: str = None,
             data: dict = None
     ) -> dict:
-        """json_field_write [summary]
-        Write data to WILL NOT CHECK IF DATA EXISTS
+        """
+        Write data to JSON field.  WILL NOT CHECK IF DATA EXISTS
         NOTE: Destructive write!
 
         Parameters
@@ -1032,11 +1034,11 @@ class AlyxClient():
             field_name: str = 'json',
             data: dict = None
     ) -> dict:
-        """json_field_update
-        Non destructive update of json field of endpoint for object
+        """
+        Non-destructive update of JSON field of endpoint for object
         Will update the field_name of the object with pk = uuid of given endpoint
         If data has keys with the same name of existing keys it will squash the old
-        values (uses the dict.update() method)
+        values (uses the dict.update() method).
 
         Parameters
         ----------
@@ -1086,8 +1088,8 @@ class AlyxClient():
             field_name: str = 'json',
             key: str = None
     ) -> Optional[dict]:
-        """json_field_remove_key
-        Will remove inputted key from json field dict and re-upload it to Alyx.
+        """
+        Remove inputted key from JSON field dict and re-upload it to Alyx.
         Needs endpoint, uuid and json field name
 
         Parameters
diff --git a/setup.py b/setup.py
index c34eafd..9c2e778 100644
--- a/setup.py
+++ b/setup.py
@@ -24,7 +24,7 @@ with open('requirements.txt') as f:
 
 setup(
     name='ONE-api',
-    version='1.6.1',
+    version='1.6.2',
     python_requires='>={}.{}'.format(*REQUIRED_PYTHON),
     description='Open Neurophysiology Environment',
     license="MIT",
-- 
GitLab