Skip to content

Commit

Permalink
Add response param to exceptions derived from HTTPError
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Oct 5, 2023
1 parent 0a6afef commit 4952b2f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pyinaturalist/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def get_access_token(
if all(payload.values()):
logger.info('Retrieved credentials from keyring')
else:
raise AuthenticationError('Not all authentication parameters were provided')
raise AuthenticationError(
'Not all authentication parameters were provided', response=response
)

# Get OAuth access token
response = session.post(f'{API_V0}/oauth/token', json=payload)
Expand Down
2 changes: 1 addition & 1 deletion pyinaturalist/v0/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,5 @@ def delete_observation(observation_id: int, **params):
**params,
)
if response.status_code == 404:
raise ObservationNotFound
raise ObservationNotFound(response=response)
response.raise_for_status()
2 changes: 1 addition & 1 deletion pyinaturalist/v1/controlled_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ def get_controlled_terms_for_taxon(taxon_id: int, **params) -> JsonResponse:

# This endpoint returns a 422 if the specified taxon does not exist
if response.status_code in (404, 422):
raise TaxonNotFound
raise TaxonNotFound(response=response)
return response.json()
4 changes: 2 additions & 2 deletions pyinaturalist/v1/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def delete_observation(observation_id: int, access_token: Optional[str] = None,
**params,
)
if response.status_code == 404:
raise ObservationNotFound
raise ObservationNotFound(response=response)
response.raise_for_status()


Expand Down Expand Up @@ -592,4 +592,4 @@ def get_observation(
response = get_observations(id=observation_id, access_token=access_token, **params)
if response['results']:
return convert_observation_timestamps(response['results'][0])
raise ObservationNotFound()
raise ObservationNotFound(response=response)

0 comments on commit 4952b2f

Please sign in to comment.