CC-2524:MusicDir.php: adding error handling

- following functions now handle error and return code and
error message if there is an error:
addDir(), setStorDir(), removeWatchedDir()
- fixed airtime-importy.py to work with new MusicDir functions
This commit is contained in:
james 2011-07-11 14:00:31 -04:00
parent ece84a04c5
commit e47f80802e
4 changed files with 48 additions and 23 deletions

View file

@ -46,10 +46,10 @@ def watch_add(args):
if(os.path.isdir(args.path)):
res = api_client.add_watched_dir(args.path)
# sucess
if(res == '[]'):
if(res['msg']['code'] == 0):
print "%s added to watched folder list successfully" % args.path
else:
print "Adding %s to watched folder list failed.( path already exist in the list )" % args.path
print "Adding a watched folder failed. : %s" % res['msg']['error']
else:
print "Given path is not a directory: %s" % args.path
@ -69,10 +69,10 @@ def watch_remove(args):
if(os.path.isdir(args.path)):
res = api_client.remove_watched_dir(args.path)
# sucess
if(res == '[]'):
if(res['msg']['code'] == 0):
print "%s removed from watched folder list successfully" % args.path
else:
print "Removing %s from watched folder list failed.( path doesn't exist in the list )" % args.path
print "Removing a watched folder failed. : %s" % res['msg']['error']
else:
print "Given path is not a directory: %s" % args.path
@ -80,10 +80,10 @@ def set_stor_dir(args):
if(os.path.isdir(args.path)):
res = api_client.set_storage_dir(args.path)
# sucess
if(res == '[]'):
if(res['msg']['code'] == 0):
print "Successfully set storage folder to %s" % args.path
else:
print "Setting storage folder to %s failed." % args.path
print "Setting storage folder to failed.: %s" % res['msg']['error']
else:
print "Given path is not a directory: %s" % args.path

View file

@ -464,6 +464,7 @@ class AirTimeApiClient(ApiClientInterface):
req = urllib2.Request(url)
response = urllib2.urlopen(req).read()
response = json.loads(response)
except Exception, e:
response = None
logger.error("Exception: %s", e)
@ -480,7 +481,7 @@ class AirTimeApiClient(ApiClientInterface):
req = urllib2.Request(url)
response = urllib2.urlopen(req).read()
#response = json.loads(response)
response = json.loads(response)
except Exception, e:
response = None
logger.error("Exception: %s", e)
@ -497,7 +498,7 @@ class AirTimeApiClient(ApiClientInterface):
req = urllib2.Request(url)
response = urllib2.urlopen(req).read()
#response = json.loads(response)
response = json.loads(response)
except Exception, e:
response = None
logger.error("Exception: %s", e)