Skip to content

Commit 49b7414

Browse files
authored
Merge pull request #24 from NohSeho/improve/return-error-code-when-http-not-200
Improve/return error code when http not 200
2 parents d17d3db + 35f79d2 commit 49b7414

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

README.rst

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ Python 사용자를 위한 아임포트 REST API 연동 모듈입니다.
103103
except Iamport.ResponseError as e:
104104
print e.code
105105
print e.message # 에러난 이유를 알 수 있음
106-
106+
except Iamport.HttpError as http_error:
107+
print http_error.code
108+
print http_error.reason # HTTP not 200 에러난 이유를 알 수 있음
107109
108110
비인증 결제
109111
-------------
@@ -129,7 +131,9 @@ Python 사용자를 위한 아임포트 REST API 연동 모듈입니다.
129131
except Iamport.ResponseError as e:
130132
# 응답 에러 처리
131133
pass
132-
134+
except Iamport.HttpError as http_error:
135+
# HTTP not 200 응답 에러 처리
136+
pass
133137
134138
저장된 빌링키로 재결제합니다.
135139

@@ -149,7 +153,9 @@ Python 사용자를 위한 아임포트 REST API 연동 모듈입니다.
149153
except Iamport.ResponseError as e:
150154
# 응답 에러 처리
151155
pass
152-
156+
except Iamport.HttpError as http_error:
157+
# HTTP not 200 응답 에러 처리
158+
pass
153159
154160
정기 예약 결제
155161
----------------
@@ -190,6 +196,9 @@ Python 사용자를 위한 아임포트 REST API 연동 모듈입니다.
190196
except Iamport.ResponseError as e:
191197
# 응답 에러 처리
192198
pass
199+
except Iamport.HttpError as http_error:
200+
# HTTP not 200 응답 에러 처리
201+
pass
193202
194203
정기 결제 예약을 취소합니다.
195204

@@ -208,7 +217,9 @@ Python 사용자를 위한 아임포트 REST API 연동 모듈입니다.
208217
except Iamport.ResponseError as e:
209218
# 응답 에러 처리
210219
pass
211-
220+
except Iamport.HttpError as http_error:
221+
# HTTP not 200 응답 에러 처리
222+
pass
212223
213224
결제 사전 검증
214225
----------------
@@ -225,7 +236,9 @@ Python 사용자를 위한 아임포트 REST API 연동 모듈입니다.
225236
except Iamport.ResponseError as e:
226237
# 응답 에러 처리
227238
pass
228-
239+
except Iamport.HttpError as http_error:
240+
# HTTP not 200 응답 에러 처리
241+
pass
229242
230243
등록된 사전정보를 확인합니다
231244

@@ -239,6 +252,9 @@ Python 사용자를 위한 아임포트 REST API 연동 모듈입니다.
239252
except Iamport.ResponseError as e:
240253
# 응답 에러 처리
241254
pass
255+
except Iamport.HttpError as http_error:
256+
# HTTP not 200 응답 에러 처리
257+
pass
242258
243259
244260
개발환경 및 테스트 설정

iamport/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ def __init__(self, code=None, message=None):
2323
self.code = code
2424
self.message = message
2525

26+
class HttpError(Exception):
27+
def __init__(self, code=None, reason=None):
28+
self.code = code
29+
self.reason = reason
30+
2631
@staticmethod
2732
def get_response(response):
2833
if response.status_code != requests.codes.ok:
29-
return {}
34+
raise Iamport.HttpError(response.status_code, response.reason)
3035
result = response.json()
3136
if result['code'] != 0:
3237
raise Iamport.ResponseError(result.get('code'), result.get('message'))

tests/test_find.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
def test_find(iamport):
66
with pytest.raises(KeyError):
77
iamport.find()
8-
result = iamport.find(imp_uid='test')
9-
assert dict == type(result)
10-
result = iamport.find(merchant_uid='test')
11-
assert dict == type(result)
8+
with pytest.raises(iamport.HttpError):
9+
iamport.find(imp_uid='test')
10+
with pytest.raises(iamport.HttpError):
11+
iamport.find(merchant_uid='âàáaā')

0 commit comments

Comments
 (0)