@@ -100,7 +100,7 @@ def __eq__(self, other):
100100 return NotImplemented
101101
102102
103- def _handle_api_error_with_json (http_exc , jsondata , response ):
103+ def _handle_api_error_with_json (http_exc , jsondata , response , request_data ):
104104 """Handle YOURLS API errors.
105105
106106 requests' raise_for_status doesn't show the user the YOURLS json response,
@@ -110,7 +110,11 @@ def _handle_api_error_with_json(http_exc, jsondata, response):
110110 code = jsondata ['code' ]
111111 message = jsondata ['message' ]
112112
113- if code == 'error:noloop' :
113+ if code == 'error:keyword' :
114+ # In YOURLS 1.9 or later, we get HTTP 400, so we should handle duplicate
115+ # keyword here.
116+ raise YOURLSKeywordExistsError (message , keyword = request_data ['keyword' ])
117+ elif code == 'error:noloop' :
114118 raise YOURLSNoLoopError (message , response = response )
115119 elif code == 'error:nourl' :
116120 raise YOURLSNoURLError (message , response = response )
@@ -142,7 +146,7 @@ def _validate_yourls_response(response, data):
142146 else :
143147 logger .debug ('Received error {response} with JSON {json}' ,
144148 response = response , json = jsondata )
145- _handle_api_error_with_json (http_exc , jsondata , response )
149+ _handle_api_error_with_json (http_exc , jsondata , response , data )
146150
147151 if reraise :
148152 six .reraise (* http_error_info )
0 commit comments