Diff of /qiita_pet/exceptions.py [000000] .. [879b32]

Switch to unified view

a b/qiita_pet/exceptions.py
1
# -----------------------------------------------------------------------------
2
# Copyright (c) 2014--, The Qiita Development Team.
3
#
4
# Distributed under the terms of the BSD 3-clause License.
5
#
6
# The full license is in the file LICENSE, distributed with this software.
7
# -----------------------------------------------------------------------------
8
from tornado.web import HTTPError
9
10
from qiita_core.exceptions import QiitaError
11
12
13
class QiitaHTTPError(HTTPError):
14
    def __init__(self, status_code=500, log_message=None, *args, **kwargs):
15
        super(QiitaHTTPError, self).__init__(
16
            status_code, log_message, *args, **kwargs)
17
        # The HTTPError has an attribute named "reason" that will get send to
18
        # the requester if specified. However, the developer need to
19
        # specifically pass the keyword "reason" when raising the exception.
20
        # The vast majority of our code it is not using the keyword "reason"
21
        # but we are using "log_message". By setting up the attribute reason
22
        # with the value in log_message, we make sure that when the answer
23
        # is sent to the requester, it will contain a useful error message,
24
        # rather than a generic error message.
25
        if not self.reason:
26
            self.reason = log_message
27
28
29
class QiitaPetAuthorizationError(QiitaError):
30
    """When a user tries to access a resource without proper authorization"""
31
    def __init__(self, user_id, resource_name_str):
32
        super(QiitaPetAuthorizationError, self).__init__()
33
        self.args = ("User %s is not authorized to access %s"
34
                     % (user_id, resource_name_str),)