Commit 5d4f5c57 authored by okhin's avatar okhin 🚴

Merge branch '5-fix-unauthorized-calls' into 'master'

Raise eception in the event_handler too

Closes #5

See merge request !21
parents ee558e44 b9540f0b
Pipeline #945 passed with stage
in 5 seconds
...@@ -266,7 +266,10 @@ class Call(object): ...@@ -266,7 +266,10 @@ class Call(object):
''' '''
state = event['type'] state = event['type']
if state in self.actions: if state in self.actions:
getattr(self, self.actions[state])(event=event) try:
getattr(self, self.actions[state])(event=event)
except Exception as e:
raise e
def hangup(self, event): def hangup(self, event):
''' '''
...@@ -319,6 +322,10 @@ class Call(object): ...@@ -319,6 +322,10 @@ class Call(object):
channel.originate(endpoint) channel.originate(endpoint)
except AssertionError as e: except AssertionError as e:
phone_logger.error("Received a DTMF sequence out le being in a '{}' state, ignoring: {}".format(self.state, event['digit'])) phone_logger.error("Received a DTMF sequence out le being in a '{}' state, ignoring: {}".format(self.state, event['digit']))
raise e
except ValueError as e:
phone_logger.error("Incorrect number: {}".format(e.message,))
raise e
def change(self, event): def change(self, event):
''' '''
...@@ -389,7 +396,6 @@ class Call(object): ...@@ -389,7 +396,6 @@ class Call(object):
self.db.commit() self.db.commit()
except Exception as e: except Exception as e:
bottle_logger.exception(e) bottle_logger.exception(e)
phone_logger.exception(e)
raise e raise e
def start(db): def start(db):
...@@ -466,6 +472,9 @@ def originate(db, callid=None): ...@@ -466,6 +472,9 @@ def originate(db, callid=None):
, 'user': request.params['api'] , 'user': request.params['api']
, 'hits': 1} , 'hits': 1}
return {'header': head, 'data': call} return {'header': head, 'data': call}
except ValueError as e:
bottle_logger.exception(e)
abort(403, "Your phone number isnt' authorized to use the piphone")
except Exception as e: except Exception as e:
bottle_logger.debug("Missing params : {}".format([p for p in request.params],)) bottle_logger.debug("Missing params : {}".format([p for p in request.params],))
bottle_logger.exception(e) bottle_logger.exception(e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment