Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Changes

### Fixes
* fix #48 - raise PHPyPAMEntityNotFoundException if searching for non existing host

### Breaks

Expand Down
23 changes: 12 additions & 11 deletions phpypam/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ class PHPyPAMException(Exception):
This exception is raised if anythings in :class:`phpypam.api` doesn't work out.
"""

_NOT_FOUND_MESSAGES = {
'No subnets found',
'Address not found',
'Vlan not found',
'No vrfs configured',
'No devices configured',
'No results (filter applied)',
'No objects found',
'Hostname not found'
}

def __init__(self, *args, code=None, message=None):
"""Generate PHPyPAMException.

Expand All @@ -24,17 +35,7 @@ def __init__(self, *args, code=None, message=None):
self._code = code
self._message = message

_NOT_FOUND_MESSAGES = {
'No subnets found',
'Address not found',
'Vlan not found',
'No vrfs configured',
'No devices configured',
'No results (filter applied)',
'No objects found',
}

if (self._code == 200 and self._message in _NOT_FOUND_MESSAGES) or self._code == 404:
if (self._code == 200 and self._message in self._NOT_FOUND_MESSAGES) or self._code == 404:
raise PHPyPAMEntityNotFoundException(self._message)
elif self._code == 500:
if self._message == 'Invalid username or password':
Expand Down
Loading