Coverage for marvin.utils : 93%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" marvin.utils ~~~~~~~~~~~~
A collection of utilities that might be handy in several places in the marvin code.
"""
""" Base API class used to add some extra functionality to Flask-RESTful. """ # pylint: disable=super-on-old-class
'application/json': _fastjson, }
""" Override handle_error to make sure the exception is handled by the correct logger. """ # Don't do any special logging of client side errors
""" Replace the default json serializer with one based on ujson. """
""" Handles errors outside the API, ie in blueprints. """ 'msg': "Oops, server fault! We'll try to fix it ASAP, hang tight!", }
""" Log exception to the standard marvin logger. """ Path: %s Params: %s HTTP Method: %s Client IP Address: %s User Agent: %s User Platform: %s User Browser: %s User Browser Version: %s HTTP Headers: %s Exception: %s """ % ( request.path, request.values, request.method, request.remote_addr, request.user_agent.string, request.user_agent.platform, request.user_agent.browser, request.user_agent.version, request.headers, exception ) ) #sysout seems a bit eradic for the loggers, so if any tests fail, you might want to uncomment these lines # print(log_msg) # import traceback # traceback.print_exc()
""" Commits the session if no error has occured, otherwise rollbacks. """ except Exception: # pylint: disable=broad-except # Whoops, a little too late too modify the response, but rollback the session # and make sure the exception is logged db.session.rollback() _logger.exception('Exception happened during teardown commit.') else: # We have an exception, but it has probably already been handled by the approriate handlers, # so just rollback the session and ignore the error |