X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2common%2Fauthmw%2Fauthmiddleware.py;h=13be91013885a57f91127fecc9433bef5f0bafbc;hb=102f6523af2b9490181be8aca42af7696269e2eb;hp=c70adfcf7dc8a88785f572be542eb6728205a0aa;hpb=14fc8de3f80b6e1ab1e8351017383e99628cb8e3;p=pti%2Fo2.git diff --git a/o2common/authmw/authmiddleware.py b/o2common/authmw/authmiddleware.py index c70adfc..13be910 100644 --- a/o2common/authmw/authmiddleware.py +++ b/o2common/authmw/authmiddleware.py @@ -43,6 +43,11 @@ def _response_wrapper(environ, start_response, header): return res(environ, start_response) +def _internal_err_response_wrapper(environ, start_response): + res = Response(mimetype='text/plain', status=500) + return res(environ, start_response) + + class authmiddleware(): ''' @@ -67,7 +72,15 @@ class authmiddleware(): if ret is True: logger.info( "auth success with oauth token: " + auth_token) - return self.app(environ, start_response) + try: + return self.app(environ, start_response) + except Exception as ex: + logger.error( + 'Internal exception happend \ + ed {}'.format(str(ex)), exc_info=True) + return \ + _internal_err_response_wrapper(environ, + start_response) else: raise AuthFailureExp( 'Bearer realm="Authentication Failed"') @@ -77,7 +90,7 @@ class authmiddleware(): return _response_wrapper(environ, start_response, ex.dictize()) except AuthFailureExp as ex: return _response_wrapper(environ, start_response, ex.dictize()) - except Exception: - hint = 'Bearer realm="Authentication Required"' - return _response_wrapper(environ, start_response, - AuthRequiredExp(hint).dictize()) + except Exception as ex: + logger.error('Internal exception happended {}'.format( + str(ex)), exc_info=True) + return _internal_err_response_wrapper(environ, start_response)