OSDN Git Service

remove system collection
[simple-tornado-bot/simple-tornado-bot.git] / linebot / exceptions.py
1 # -*- coding: utf-8 -*-
2
3 #  Licensed under the Apache License, Version 2.0 (the "License"); you may
4 #  not use this file except in compliance with the License. You may obtain
5 #  a copy of the License at
6 #
7 #       https://www.apache.org/licenses/LICENSE-2.0
8 #
9 #  Unless required by applicable law or agreed to in writing, software
10 #  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 #  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 #  License for the specific language governing permissions and limitations
13 #  under the License.
14
15 """linebot.exceptions module."""
16
17 from __future__ import unicode_literals
18
19 from abc import ABCMeta
20
21 from future.utils import with_metaclass
22
23
24 class BaseError(with_metaclass(ABCMeta, Exception)):
25     """Base Exception class."""
26
27     def __init__(self, message='-'):
28         """__init__ method.
29
30         :param str message: Human readable message
31         """
32         self.message = message
33
34     def __repr__(self):
35         """repr.
36
37         :return:
38         """
39         return str(self)
40
41     def __str__(self):
42         """str.
43
44         :rtype: str
45         :return:
46         """
47         return '<{0} [{1}]>'.format(
48             self.__class__.__name__, self.message)
49
50
51 class InvalidSignatureError(BaseError):
52     """When Webhook signature does NOT match, this error will be raised."""
53
54     def __init__(self, message='-'):
55         """__init__ method.
56
57         :param str message: Human readable message
58         """
59         super(InvalidSignatureError, self).__init__(message)
60
61
62 class LineBotApiError(BaseError):
63     """When LINE Messaging API response error, this error will be raised."""
64
65     def __init__(self, status_code, error=None):
66         """__init__ method.
67
68         :param int status_code: http status code
69         :param error: (optional) Error class object.
70         :type error: :py:class:`linebot.models.error.Error`
71         """
72         super(LineBotApiError, self).__init__(error.message)
73
74         self.status_code = status_code
75         self.error = error
76
77     def __str__(self):
78         """str.
79
80         :rtype: str
81         :return:
82         """
83         return '{0}: status_code={1}, error_response={2}'.format(
84             self.__class__.__name__, self.status_code, self.error)