diff options
| author | Goffin Simon <simon.goffin@outlook.com> | 2014-12-18 16:38:09 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2015-01-16 17:15:18 +0100 |
| commit | 0fd773a486fbc1aeef7f00ec5eab3eaf0e4c6a9d (patch) | |
| tree | e0b6ab3c1d7c21a2539235805912ee82efd4f23a /addons/mail/mail_message.py | |
| parent | eeb8ed165d713f41d7cde33e46acd7accef722fb (diff) | |
[IMP] Cleanup and refactoring of exception handling
Unify and refactor exception handling in framework and addons.
The generic `except_osv` is now deprecated, and replaced by more specialized exception subtypes:
- `UserError` (renamed from Warning, as it conflicts with the built-in `Warning`) raised when a non-technical error occurs during a business operation. It could be a missing information in the data provided by the user, or a misconfiguration.
- `AccessError`: raised when any operation is denied because the user conducting it does not have the required access rights.
- `AccessDenied`: raised when an operation that requires authenticated access is attempted via an unauthenticated request.
- `MissingError`: raised when an operation is attempted on a record that does not exist.
- `ValidationError`: raised when an operation violates a SQL or Python constraint.
- All other exceptions are internal errors due to a system problem or bug, and raised untouched to the client-side, which should display a traceback.
All exceptions take a single message argument.
The `test_exceptions` module has been updated to showcase both new and old (deprecated) exceptions.
A great many old `except_osv` had a useless title with "Error!" or "Warning", those have been removed, as this is handled by the client-side widget that displays the messages.
This commit introduces a more consistent policy for logging errors and warnings:
- All messages that do not require administrator attention should be logged at INFO level or lower. This includes all errors that are notified to the user in a friendly manner, even for access right problems or validation errors during business operations.
- All messages that indicate a likely misconfiguration or malicious use by the users should be logged at WARNING level, as they typically require administrator attention.
- All other unhandled internal errors cannot typically be handled by the user and should be logged at ERROR or higher level, as they require immediate administrator attention.
Diffstat (limited to 'addons/mail/mail_message.py')
| -rw-r--r-- | addons/mail/mail_message.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index fe433657077..2780a659008 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -26,10 +26,11 @@ from openerp import tools from email.header import decode_header from email.utils import formataddr from openerp import SUPERUSER_ID, api -from openerp.osv import osv, orm, fields +from openerp.osv import osv, fields from openerp.tools import html_email_clean from openerp.tools.translate import _ from HTMLParser import HTMLParser +from openerp.exceptions import UserError, AccessError _logger = logging.getLogger(__name__) @@ -174,7 +175,7 @@ class mail_message(osv.Model): return formataddr((this.name, '%s@%s' % (this.alias_name, this.alias_domain))) elif this.email: return formataddr((this.name, this.email)) - raise osv.except_osv(_('Invalid Action!'), _("Unable to send email, please configure the sender's email address or alias.")) + raise UserError(_("Unable to send email, please configure the sender's email address or alias.")) def _get_default_author(self, cr, uid, context=None): return self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context).partner_id.id @@ -770,10 +771,10 @@ class mail_message(osv.Model): other_ids = other_ids.difference(set(document_related_ids)) if not other_ids: return - raise orm.except_orm(_('Access Denied'), - _('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % + raise AccessError(_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % (self._description, operation)) + def _get_record_name(self, cr, uid, values, context=None): """ Return the related document name, using name_get. It is done using SUPERUSER_ID, to be sure to have the record name correctly stored. """ |
