April 2019
Beginner to intermediate
774 pages
24h 59m
English
Sometimes, you are working on error-prone code, meaning that the operation you are performing may generate an error. Odoo will catch this error and display a traceback to the user. If you don't want to show a full error log to the user, you can cache the error and raise a custom exception with a meaningful message. In the given example, we are generating UserError from the try...cache block so that instead of showing a full error log, Odoo will now show a warning with a meaningful message:
def post_to_webservice(self, data): try: req = requests.post('http://my-test-service.com', data=data, timeout=10) content = req.json() except IOError: error_msg = _("Something went wrong during data submission") raise UserError(error_msg) ...Read now
Unlock full access