galaxy-dist commit 4187ae2fdb9e: Improved error handling in api methods.
# HG changeset patch -- Bitbucket.org # Project galaxy-dist # URL http://bitbucket.org/galaxy/galaxy-dist/overview # User rc # Date 1289186302 18000 # Node ID 4187ae2fdb9e3f8b7ff5878e7517a24868b8ffca # Parent dcc68da403f0e8d3ae0da07529ff96327ca05489 Improved error handling in api methods. --- a/scripts/api/common.py +++ b/scripts/api/common.py @@ -48,6 +48,13 @@ def put( api_key, url, data ): req.get_method = lambda: 'PUT' return simplejson.loads( urllib2.urlopen( req ).read() ) +def __del( api_key, url, data ): + # Do the actual DELETE + url = make_url( api_key, url ) + req = urllib2.Request( url, headers = { 'Content-Type': 'application/json' }, data = simplejson.dumps( data )) + req.get_method = lambda: 'DELETE' + return simplejson.loads( urllib2.urlopen( req ).read() ) + def display( api_key, url, return_formatted=True ): # Sends an API GET request and acts as a generic formatter for the JSON response. @@ -89,12 +96,12 @@ def submit( api_key, url, data, return_f try: r = post( api_key, url, data ) except urllib2.HTTPError, e: - print e - print e.read( 1024 ) if return_formatted: + print e + print e.read( 1024 ) sys.exit( 1 ) else: - return 'Error. '+ str( e ) + return 'Error. '+ str( e.read( 1024 ) ) if not return_formatted: return r print 'Response' @@ -123,30 +130,35 @@ def update( api_key, url, data, return_f try: r = put( api_key, url, data ) except urllib2.HTTPError, e: - print e - print e.read( 1024 ) - sys.exit( 1 ) + if return_formatted: + print e + print e.read( 1024 ) + sys.exit( 1 ) + else: + return 'Error. '+ str( e.read( 1024 ) ) if not return_formatted: return r print 'Response' print '--------' - if type( r ) == list: - # Currently the only implemented responses are lists of dicts, because - # submission creates some number of collection elements. - for i in r: - if type( i ) == dict: - if 'url' in i: - print i.pop( 'url' ) - else: - print '----' - if 'name' in i: - print ' name: %s' % i.pop( 'name' ) - for k, v in i.items(): - print ' %s: %s' % ( k, v ) - else: - print i - else: - print r + print r + +def delete( api_key, url, data, return_formatted=True ): + # Sends an API DELETE request and acts as a generic formatter for the JSON response. + # 'data' will become the JSON payload read by Galaxy. + try: + r = __del( api_key, url, data ) + except urllib2.HTTPError, e: + if return_formatted: + print e + print e.read( 1024 ) + sys.exit( 1 ) + else: + return 'Error. '+ str( e.read( 1024 ) ) + if not return_formatted: + return r + print 'Response' + print '--------' + print r # utility method to encode ID's def encode_id( config_id_secret, obj_id ): --- a/scripts/galaxy_messaging/server/amqp_consumer.py +++ b/scripts/galaxy_messaging/server/amqp_consumer.py @@ -95,7 +95,7 @@ def update_request( api_key, request_id try: retval = api.update( api_key, url, data, return_formatted=False ) log.debug( str( retval ) ) - except urllib2.URLError, e: + except Exception, e: log.debug( 'ERROR(update_request (%s)): %s' % ( str((self.api_key, url, data)), str(e) ) ) def recv_callback( message ): --- a/lib/galaxy/web/controllers/requests_admin.py +++ b/lib/galaxy/web/controllers/requests_admin.py @@ -662,7 +662,7 @@ class RequestsAdmin( BaseController, Use except Exception, e: err_msg = "Error in sending the data transfer message to the Galaxy AMQP message queue:<br/>%s" % str(e) if not err_msg: - message = "%i datasets have been queued for transfer from the sequencer. Click the Refresh button above to monitor the transfer status." % len( selected_sample_datasets ) + err_msg = "%i datasets have been queued for transfer from the sequencer. Click the Refresh button above to monitor the transfer status." % len( selected_sample_datasets ) status = "done" else: status = 'error' @@ -670,7 +670,7 @@ class RequestsAdmin( BaseController, Use action='manage_datasets', sample_id=trans.security.encode_id( sample.id ), status=status, - message=message ) ) + message=err_msg ) ) @web.expose def update_sample_dataset_status(self, trans, cntrller, sample_dataset_ids, new_status, error_msg=None ): # check if the new status is a valid transfer status
participants (1)
-
commits-noreply@bitbucket.org