[973924]: / qiita_pet / exceptions.py

Download this file

35 lines (29 with data), 1.6 kB

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