From a31a031b3b2bb27ba04b37f5a05790c207c7d00b Mon Sep 17 00:00:00 2001 From: John Chilton Date: Thu, 25 Dec 2014 12:24:23 -0500 Subject: [PATCH] Update datatypes API to newer API decoarator/exception handling. --- lib/galaxy/webapps/galaxy/api/datatypes.py | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/datatypes.py b/lib/galaxy/webapps/galaxy/api/datatypes.py index 7299cfe0bb9..47b9b56de65 100644 --- a/lib/galaxy/webapps/galaxy/api/datatypes.py +++ b/lib/galaxy/webapps/galaxy/api/datatypes.py @@ -2,7 +2,8 @@ API operations allowing clients to determine datatype supported by Galaxy. """ -from galaxy import web +from galaxy.web import _future_expose_api_anonymous as expose_api_anonymous +from galaxy import exceptions from galaxy.web.base.controller import BaseAPIController from galaxy.util import asbool from galaxy.datatypes.data import Data @@ -13,7 +14,7 @@ log = logging.getLogger( __name__ ) class DatatypesController( BaseAPIController ): - @web.expose_api_anonymous + @expose_api_anonymous def index( self, trans, **kwd ): """ GET /api/datatypes @@ -38,12 +39,14 @@ class DatatypesController( BaseAPIController ): dictionary[key] = elem.get(key) rval.append(dictionary) return rval - except Exception, exception: + except Exception as exception: log.error( 'could not get datatypes: %s', str( exception ), exc_info=True ) - trans.response.status = 500 - return { 'error': str( exception ) } + if not isinstance( exception, exceptions.MessageException ): + raise exceptions.InternalServerError( str( exception ) ) + else: + raise - @web.expose_api_anonymous + @expose_api_anonymous def mapping( self, trans, **kwd ): ''' GET /api/datatypes/mapping @@ -69,12 +72,15 @@ class DatatypesController( BaseAPIController ): visit_bases( types, c ) class_to_classes[ n ] = dict( ( t, True ) for t in types ) return dict( ext_to_class_name=ext_to_class_name, class_to_classes=class_to_classes ) - except Exception, exception: - log.error( 'could not get datatype mapping: %s', str( exception ), exc_info=True ) - trans.response.status = 500 - return { 'error': str( exception ) } - @web.expose_api_anonymous + except Exception as exception: + log.error( 'could not get datatype mapping: %s', str( exception ), exc_info=True ) + if not isinstance( exception, exceptions.MessageException ): + raise exceptions.InternalServerError( str( exception ) ) + else: + raise + + @expose_api_anonymous def sniffers( self, trans, **kwd ): ''' GET /api/datatypes/sniffers @@ -87,7 +93,9 @@ class DatatypesController( BaseAPIController ): if datatype is not None: rval.append( datatype ) return rval - except Exception, exception: + except Exception as exception: log.error( 'could not get datatypes: %s', str( exception ), exc_info=True ) - trans.response.status = 500 - return { 'error': str( exception ) } + if not isinstance( exception, exceptions.MessageException ): + raise exceptions.InternalServerError( str( exception ) ) + else: + raise