Skip to content

Commit a10b1f3

Browse files
authored
Merge pull request #80 from mattmanley/refactor_response_text
Changed response handling in case of JSON deserializing error
2 parents 9651115 + db9d1f1 commit a10b1f3

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

maproulette/api/challenge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def rebuild_challenge(self, challenge_id, remove_unmatched=False, skip_snapshot=
334334
CREATED or SKIPPED status (only) will be removed prior to rebuilding with the assumption that they will be
335335
recreated if they still appear in the updated source data. If set to false, unmatched existing tasks are
336336
simply left as-is. Default: False
337-
:param skipSnapshot: Whether to skip recording a snapshot before proceeding. Default: False
337+
:param skip_snapshot: Whether to skip recording a snapshot before proceeding. Default: False
338338
"""
339339
response = self.put(
340340
endpoint=f"/challenge/{challenge_id}/rebuild",

maproulette/api/maproulette_server.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def get(self, endpoint, params=None):
5454
5555
:param endpoint: the server endpoint to use for the GET request
5656
:param params: the parameters that pertain to the request (optional)
57-
:returns: a JSON object containing the API response
57+
:returns: a dictionary containing the API response status code as well as the decoded JSON response if decoding
58+
was successful. If not, the response text is returned.
5859
"""
5960
response = self.session.get(
6061
self.url + endpoint,
@@ -85,6 +86,7 @@ def get(self, endpoint, params=None):
8586
}
8687
except ValueError:
8788
return {
89+
"data": response.text,
8890
"status": response.status_code
8991
}
9092

@@ -94,7 +96,8 @@ def post(self, endpoint, body=None, params=None):
9496
:param endpoint: the server endpoint to use for the POST request
9597
:param body: the body of the request (optional)
9698
:param params: the parameters that pertain to the request (optional)
97-
:returns: a JSON object containing the API response
99+
:returns: a dictionary containing the API response status code as well as the decoded JSON response if decoding
100+
was successful. If not, the response text is returned.
98101
"""
99102
response = self.session.post(
100103
self.url + endpoint,
@@ -128,6 +131,7 @@ def post(self, endpoint, body=None, params=None):
128131
}
129132
except ValueError:
130133
return {
134+
"data": response.text,
131135
"status": response.status_code
132136
}
133137

@@ -137,7 +141,8 @@ def put(self, endpoint, body=None, params=None):
137141
:param endpoint: the server endpoint to use for the PUT request
138142
:param body: the body of the request (optional)
139143
:param params: the parameters that pertain to the request (optional)
140-
:returns: a JSON object containing the response code and the API response if
144+
:returns: a dictionary containing the API response status code as well as the decoded JSON response if decoding
145+
was successful. If not, the response text is returned.
141146
"""
142147
response = self.session.put(
143148
self.url + endpoint,
@@ -171,6 +176,7 @@ def put(self, endpoint, body=None, params=None):
171176
}
172177
except ValueError:
173178
return {
179+
"data": response.text,
174180
"status": response.status_code
175181
}
176182

@@ -179,7 +185,8 @@ def delete(self, endpoint, params=None):
179185
180186
:param endpoint: the server endpoint to use for the DELETE request
181187
:param params: the parameters that pertain to the request (optional)
182-
:returns: a JSON object containing the API response
188+
:returns: a dictionary containing the API response status code as well as the decoded JSON response if decoding
189+
was successful. If not, the response text is returned.
183190
"""
184191
response = self.session.delete(
185192
self.url + endpoint,
@@ -212,6 +219,7 @@ def delete(self, endpoint, params=None):
212219
}
213220
except ValueError:
214221
return {
222+
"data": response.text,
215223
"status": response.status_code
216224
}
217225

0 commit comments

Comments
 (0)