Skip to content

Commit

Permalink
Merge pull request #109 from PagerDuty/asmith/fix-path-matching
Browse files Browse the repository at this point in the history
Handle exact path matches
  • Loading branch information
Deconstrained authored Jun 7, 2023
2 parents 24a9886 + 4fe1476 commit 7684db0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pdpyras.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,16 @@ def canonical_path(base_url: str, url: str):
patterns
))
# Don't break early if len(patterns) == 1, but require an exact match...

if len(patterns) == 0:
raise URLError(f"URL {url} does not match any canonical API path " \
'supported by this client.')
elif len(patterns) > 1:
# If there's multiple matches but one matches exactly, return that.
if url_path in patterns:
return url_path

# ...otherwise this is ambiguous.
raise Exception(f"Ambiguous URL {url} matches more than one " \
"canonical path pattern: "+', '.join(patterns)+'; this is likely ' \
'a bug.')
Expand Down

0 comments on commit 7684db0

Please sign in to comment.