1 # -*- coding: utf-8 -*-
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
7 # https://www.apache.org/licenses/LICENSE-2.0
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
15 """linebot.exceptions module."""
17 from __future__ import unicode_literals
19 from abc import ABCMeta
21 from future.utils import with_metaclass
24 class BaseError(with_metaclass(ABCMeta, Exception)):
25 """Base Exception class."""
27 def __init__(self, message='-'):
30 :param str message: Human readable message
32 self.message = message
47 return '<{0} [{1}]>'.format(
48 self.__class__.__name__, self.message)
51 class InvalidSignatureError(BaseError):
52 """When Webhook signature does NOT match, this error will be raised."""
54 def __init__(self, message='-'):
57 :param str message: Human readable message
59 super(InvalidSignatureError, self).__init__(message)
62 class LineBotApiError(BaseError):
63 """When LINE Messaging API response error, this error will be raised."""
65 def __init__(self, status_code, error=None):
68 :param int status_code: http status code
69 :param error: (optional) Error class object.
70 :type error: :py:class:`linebot.models.error.Error`
72 super(LineBotApiError, self).__init__(error.message)
74 self.status_code = status_code
83 return '{0}: status_code={1}, error_response={2}'.format(
84 self.__class__.__name__, self.status_code, self.error)