diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-06-23 16:46:58 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-06-23 16:48:25 +0000 |
commit | 0b31a04a38b3a2819ab166c69d31c122723a33af (patch) | |
tree | f5c1d9f6ab6b5b5fa2ceb20dd493797725f96e8e /lorrycontroller | |
parent | e530deefe02b7f6de2748f7d99f713bc9d4abfe5 (diff) | |
download | lorry-controller-0b31a04a38b3a2819ab166c69d31c122723a33af.tar.gz |
Improve move-to-top/bottom API call error messagesliw/move-error-msgs
Diffstat (limited to 'lorrycontroller')
-rw-r--r-- | lorrycontroller/movetopbottom.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lorrycontroller/movetopbottom.py b/lorrycontroller/movetopbottom.py index 7c1664a..2aeff98 100644 --- a/lorrycontroller/movetopbottom.py +++ b/lorrycontroller/movetopbottom.py @@ -26,13 +26,25 @@ class MoveBase(object): def run(self, **kwargs): logging.info('%s %s called', self.http_method, self.path) path = bottle.request.forms.path + if not path: + return 'Form field path was not given' statedb = self.open_statedb() with statedb: + if not self.lorry_exists(statedb, path): + return 'Lorry %s does not exist' % path lorry_infos = statedb.get_all_lorries_info() timestamp = self.get_new_timestamp(lorry_infos) statedb.set_lorry_last_run(path, timestamp) return self.msg % path + def lorry_exists(self, statedb, path): + try: + statedb.get_lorry_info(path) + except lorrycontroller.LorryNotFoundError: + return False + else: + return True + class MoveToTop(MoveBase, lorrycontroller.LorryControllerRoute): |