from requests.exceptions import RequestException
from .error import BigStashError
from wrapt import decorator


@decorator
def json_response(wrapped, instance, args, kwargs):
    try:
        r = wrapped(*args, **kwargs)
        r.raise_for_status()
        return r.json()
    except RequestException:
        raise BigStashError
    except ValueError:
        raise BigStashError

from requests.exceptions import RequestException
from .error import BigStashError
from wrapt import decorator


@decorator
def json_response(wrapped, instance, args, kwargs):
    try:
        r = wrapped(*args, **kwargs)
        r.raise_for_status()
        return r.json()
    except RequestException as e:
        raise BigStashError(e)
    except ValueError as e:
        raise BigStashError(e)


@decorator
def no_content_response(wrapped, instance, args, kwargs):
    try:
        r = wrapped(*args, **kwargs)
        r.raise_for_status()
    except RequestException as e:
        raise BigStashError(e)

Add decorator for empty responses and show error messages
Add decorator for empty responses and show error messages

- Add decorator for responses with no content, like delete requests.
- Show original error messages for now

  from requests.exceptions import RequestException
  from .error import BigStashError
  from wrapt import decorator
  
  
  @decorator
  def json_response(wrapped, instance, args, kwargs):
      try:
          r = wrapped(*args, **kwargs)
          r.raise_for_status()
          return r.json()
-     except RequestException:
+     except RequestException as e:
-         raise BigStashError
+         raise BigStashError(e)
-     except ValueError:
+     except ValueError as e:
-         raise BigStashError
+         raise BigStashError(e)
  
+ 
+ @decorator
+ def no_content_response(wrapped, instance, args, kwargs):
+     try:
+         r = wrapped(*args, **kwargs)
+         r.raise_for_status()
+     except RequestException as e:
+         raise BigStashError(e)
+ 
Add decorator for empty responses and show error messages
## Code Before:
from requests.exceptions import RequestException
from .error import BigStashError
from wrapt import decorator


@decorator
def json_response(wrapped, instance, args, kwargs):
    try:
        r = wrapped(*args, **kwargs)
        r.raise_for_status()
        return r.json()
    except RequestException:
        raise BigStashError
    except ValueError:
        raise BigStashError

## Instruction:
Add decorator for empty responses and show error messages
## Code After:
from requests.exceptions import RequestException
from .error import BigStashError
from wrapt import decorator


@decorator
def json_response(wrapped, instance, args, kwargs):
    try:
        r = wrapped(*args, **kwargs)
        r.raise_for_status()
        return r.json()
    except RequestException as e:
        raise BigStashError(e)
    except ValueError as e:
        raise BigStashError(e)


@decorator
def no_content_response(wrapped, instance, args, kwargs):
    try:
        r = wrapped(*args, **kwargs)
        r.raise_for_status()
    except RequestException as e:
        raise BigStashError(e)
