iro/offer/smstrade.py
branchdevel
changeset 213 3620bacf1152
parent 186 b381eaa774ab
child 214 bacf50bc46bf
--- a/iro/offer/smstrade.py	Fri Mar 02 14:00:23 2012 +0100
+++ b/iro/offer/smstrade.py	Sat Mar 03 03:29:19 2012 +0100
@@ -19,16 +19,18 @@
 from ..config import Option
 from ..model.status import Status
 from .provider import Provider, providers
+from ..error import RejectRecipient, ExternalException
 
 import logging
 logger=logging.getLogger("smstrade")
 
-class UnknownStatusCode(Exception):
-    def __init__(self,code):
-        self.code=code
+class UnknownStatusCode(ExternalException):
+    def __init__(self,status):
+        ExternalException.__init__(self)
+        self.status=status
 
     def __str__(self):
-        return "StatusCode %i is unknown"%self.code
+        return "%s\nStatusCode %i is unknown."%(ExternalException.__str__(self),self.status)
 
 
 class StatusCode:
@@ -57,7 +59,7 @@
      
      def __str__(self):
         try:
-            return self.statusCodes[self.code]
+            return "%i: %s"%(self.code, self.statusCodes[self.code])
         except IndexError:
             raise UnknownStatusCode(self.code)
 
@@ -92,17 +94,17 @@
         route = unicode(route)
 
         if recipient.land != '49' and route == "basic":
-            return Exception()
+            raise RejectRecipient(recipient)
         
         to ='00'+recipient.land+recipient.number
-        try:
-            smsSendStatus = self.__send(route, to, sms)	
-            logger.info('smstrade._send(...)=%i(%s)'%(int(smsSendStatus),str(smsSendStatus)))
-            if int(smsSendStatus) in (100,):
-                return Status(self,route)
-            else:
-                raise Exception()
-        except UnknownStatusCode:
+        
+        smsSendStatus = self.__send(route, to, sms)	
+        logger.info('smstrade._send(...)=%i(%s)'%(int(smsSendStatus),str(smsSendStatus)))
+        if int(smsSendStatus) in (100,):
+            return Status(self,route)
+        elif int(smsSendStatus) in (70,71,):
+            raise RejectRecipient(recipient, status=smsSendStatus)
+        else:
             raise Exception()
 
     def __send(self, route, to, sms):