Skip to content

Commit

Permalink
Merge pull request #5 from diggyk/master
Browse files Browse the repository at this point in the history
0.1.14: Added better error messages when filtering by hostname
  • Loading branch information
gmjosack committed Jun 15, 2015
2 parents f9d3159 + cce7b6c commit c13aaa1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
38 changes: 22 additions & 16 deletions hermes/handlers/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ipaddress
import logging
import re
import sqlalchemy
from sqlalchemy import desc
from sqlalchemy.exc import IntegrityError

Expand Down Expand Up @@ -936,11 +937,15 @@ def get(self):
events = events.filter_by(host_id=host_id)

if hostname:
host = (
self.session.query(Host).filter(
Host.hostname == hostname
).one()
)
try:
host = (
self.session.query(Host).filter(
Host.hostname == hostname
).one()
)
except sqlalchemy.orm.exc.NoResultFound:
raise exc.BadRequest("No host {} found".format(hostname))

events = events.filter(Event.host == host)

offset, limit, expand = self.get_pagination_values()
Expand Down Expand Up @@ -1398,18 +1403,19 @@ def get(self):
labors = labors.filter(Labor.quest_id == quest_id)

if hostname is not None:
host = (
self.session.query(Host).filter(
Host.hostname == hostname
).one()
)
if host:
labors = (
labors.filter(Labor.host == host)
.order_by(desc(Labor.creation_time))
try:
host = (
self.session.query(Host).filter(
Host.hostname == hostname
).one()
)
else:
raise exc.BadRequest("Bad hostname {}".format(hostname))
except sqlalchemy.orm.exc.NoResultFound:
raise exc.BadRequest("No host {} found".format(hostname))

labors = (
labors.filter(Labor.host == host)
.order_by(desc(Labor.creation_time))
)

hostnames = []
if host_query:
Expand Down
2 changes: 1 addition & 1 deletion hermes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.12"
__version__ = "0.1.14"

0 comments on commit c13aaa1

Please sign in to comment.