Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 500 Internal Server Error with RedcapError #263

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions redcap/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
overload,
)

from requests import RequestException, Response, Session
from requests import RequestException, Response, Session, JSONDecodeError

if TYPE_CHECKING:
from io import TextIOWrapper
Expand Down Expand Up @@ -150,7 +150,10 @@ def get_content(
return [{}]

if format_type == "json":
return response.json()
try:
return response.json()
except JSONDecodeError as jde:
raise RedcapError("Unable to decode response as JSON") from jde

# don't do anything to csv/xml strings
return response.text
Expand Down Expand Up @@ -186,6 +189,9 @@ def execute(
self.url, data=self.payload, verify=verify_ssl, files=file, **kwargs
)

if response.status_code == 500:
raise RedcapError(f"HTTP error 500 {response.reason}")

content = self.get_content(
response,
format_type=self.fmt,
Expand Down