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

Add handling of forbidden errors from here api response #78

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions herepy/routing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,8 @@ def error_from_routing_service_error(json_data):
# V8 error handling
if "error" in json_data and json_data["error"] == "Unauthorized":
return InvalidCredentialsError(json_data["error_description"])
elif "error" in json_data and json_data["error"] == "Forbidden":
return InvalidCredentialsError(json_data["error_description"])
elif "status" in json_data:
error_msg = str.format(
"Cause: {0}; Action: {1}", json_data["cause"], json_data["action"]
Expand Down
4 changes: 4 additions & 0 deletions testdata/models/routing_error_forbidden_credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"error": "Forbidden",
"error_description": "These credentials do not authorize access"
}
14 changes: 14 additions & 0 deletions tests/test_routing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ def test_carroute_when_error_invalid_credentials_occurred(self):
with self.assertRaises(herepy.InvalidCredentialsError):
api.car_route([11.0, 12.0], [22.0, 23.0])

@responses.activate
def test_carroute_when_error_forbidden_credentials_occurred(self):
with open("testdata/models/routing_error_forbidden_credentials.json", "r") as f:
expectedResponse = f.read()
responses.add(
responses.GET,
"https://route.ls.hereapi.com/routing/7.2/calculateroute.json",
expectedResponse,
status=401,
)
api = herepy.RoutingApi("forbidden_api_key", "forbidden_app_code")
with self.assertRaises(herepy.InvalidCredentialsError):
api.car_route([11.0, 12.0], [22.0, 23.0])

@responses.activate
def test_carroute_when_error_no_route_found_occurred(self):
with open("testdata/models/routing_error_no_route_found.json", "r") as f:
Expand Down
Loading