[FIX] website: typos
[odoo/odoo.git] / openerp / exceptions.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2011 OpenERP s.a. (<http://openerp.com>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 """ OpenERP core exceptions.
23
24 This module defines a few exception types. Those types are understood by the
25 RPC layer. Any other exception type bubbling until the RPC layer will be
26 treated as a 'Server error'.
27
28 If you consider introducing new exceptions, check out the test_exceptions addon.
29 """
30
31 # kept for backward compatibility
32 class except_orm(Exception):
33     def __init__(self, name, value):
34         self.name = name
35         self.value = value
36         self.args = (name, value)
37
38 class Warning(Exception):
39     pass
40
41 class RedirectWarning(Exception):
42     """ Warning with a possibility to redirect the user instead of simply
43     diplaying the warning message.
44
45     Should receive as parameters:
46       :param int action_id: id of the action where to perform the redirection
47       :param string button_text: text to put on the button that will trigger
48           the redirection.
49     """
50
51 class AccessDenied(Exception):
52     """ Login/password error. No message, no traceback. """
53     def __init__(self):
54         super(AccessDenied, self).__init__('Access denied.')
55         self.traceback = ('', '', '')
56
57 class AccessError(except_orm):
58     """ Access rights error. """
59     def __init__(self, msg):
60         super(AccessError, self).__init__('AccessError', msg)
61
62 class MissingError(except_orm):
63     """ Missing record(s). """
64     def __init__(self, msg):
65         super(MissingError, self).__init__('MissingError', msg)
66
67 class ValidationError(except_orm):
68     def __init__(self, msg):
69         super(ValidationError, self).__init__('ValidateError', msg)
70
71 class DeferredException(Exception):
72     """ Exception object holding a traceback for asynchronous reporting.
73
74     Some RPC calls (database creation and report generation) happen with
75     an initial request followed by multiple, polling requests. This class
76     is used to store the possible exception occuring in the thread serving
77     the first request, and is then sent to a polling request.
78
79     ('Traceback' is misleading, this is really a exc_info() triple.)
80     """
81     def __init__(self, msg, tb):
82         self.message = msg
83         self.traceback = tb
84
85 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: