Skip to content

Commit 84b100c

Browse files
authored
Improve __str__ of LineBotApiError (#112)
* Improve __str__ of LineBotApiError * Add http status code into __str__
1 parent 3cd0ea9 commit 84b100c

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

linebot/exceptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,12 @@ def __init__(self, status_code, error=None):
7373

7474
self.status_code = status_code
7575
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)

tests/test_exceptions.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
from __future__ import unicode_literals, absolute_import
16+
17+
import unittest
18+
19+
from linebot.exceptions import LineBotApiError
20+
from linebot.models import Error, ErrorDetail
21+
22+
23+
class TestUtils(unittest.TestCase):
24+
def test_str(self):
25+
line_bot_api_error = LineBotApiError(
26+
400,
27+
error=Error(message='The request body has 1 error(s)',
28+
details=[ErrorDetail(message='May not be empty',
29+
property='messages[0].text')]))
30+
self.assertEqual(line_bot_api_error.__str__(),
31+
'LineBotApiError: status_code=400, error_response={"details": '
32+
'[{"message": "May not be empty", "property": "messages[0].text"}], '
33+
'"message": "The request body has 1 error(s)"}')
34+
35+
36+
if __name__ == '__main__':
37+
unittest.main()

0 commit comments

Comments
 (0)