-
How to called except block to allow converting exceptions to arbitrary
over 9 years ago
over 9 years ago
To Called within an except block to allow converting exceptions to arbitrary responses. Anything returned (except None) will be used as response. use this code given below in openerp.
- def _handle_exception(self, exception):
- """Called within an except block to allow converting exceptions
- to arbitrary responses. Anything returned (except None) will
- be used as response."""
- try:
- return super(JsonRequest, self)._handle_exception(exception)
- except Exception:
- if not isinstance(exception, (openerp.exceptions.Warning, SessionExpiredException, openerp.exceptions.except_orm)):
- _logger.exception("Exception during JSON request handling.")
- error = {
- 'code': 200,
- 'message': "Odoo Server Error",
- 'data': serialize_exception(exception)
- }
- if isinstance(exception, AuthenticationError):
- error['code'] = 100
- error['message'] = "Odoo Session Invalid"
- if isinstance(exception, SessionExpiredException):
- error['code'] = 100
- error['message'] = "Odoo Session Expired"
- return self._json_response(error=error)
def _handle_exception(self, exception): """Called within an except block to allow converting exceptions to arbitrary responses. Anything returned (except None) will be used as response.""" try: return super(JsonRequest, self)._handle_exception(exception) except Exception: if not isinstance(exception, (openerp.exceptions.Warning, SessionExpiredException, openerp.exceptions.except_orm)): _logger.exception("Exception during JSON request handling.") error = { 'code': 200, 'message': "Odoo Server Error", 'data': serialize_exception(exception) } if isinstance(exception, AuthenticationError): error['code'] = 100 error['message'] = "Odoo Session Invalid" if isinstance(exception, SessionExpiredException): error['code'] = 100 error['message'] = "Odoo Session Expired" return self._json_response(error=error)
Can you help out the community by solving one of the following Automation problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)