Skip to content

Commit

Permalink
fix delete op
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelliao committed Jan 21, 2023
1 parent 854a1ca commit 573d107
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions github.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*-coding: utf8 -*-

'''
Expand Down Expand Up @@ -264,7 +264,7 @@ def _http(self, _method, _path, _data=None, **kw):
params = None
if _method=='GET' and kw:
_path = '%s?%s' % (_path, _encode_params(kw))
if _method in ['POST', 'PATCH', 'PUT']:
if _method in ['POST', 'PATCH', 'PUT', 'DELETE']:
data = bytes(_encode_json(_data), 'utf-8')
url = f'{_URL}{_path}'
headers = {
Expand Down Expand Up @@ -299,11 +299,9 @@ def _http(self, _method, _path, _data=None, **kw):
json = _parse_json(e.read().decode('utf-8'))
else:
json = e.read().decode('utf-8')
req = JsonObject(method=_method, url=url)
resp = JsonObject(code=e.code, json=json)
if resp.code==404:
raise ApiNotFoundError(url, req, resp)
raise ApiError(url, req, resp)
if e.code == 404:
raise ApiNotFoundError(url)
raise ApiError(e.code, url)

def _process_resp(self, headers):
is_json = False
Expand Down Expand Up @@ -335,18 +333,20 @@ def __setattr__(self, attr, value):

class ApiError(Exception):

def __init__(self, url, request, response):
def __init__(self, code, url):
super(ApiError, self).__init__(url)
self.request = request
self.response = response
self.code = code

class ApiAuthError(ApiError):

def __init__(self, msg):
super(ApiAuthError, self).__init__(msg, None, None)
def __init__(self, code, url):
super(ApiAuthError, self).__init__(code, url)

class ApiNotFoundError(ApiError):
pass

def __init__(self, url):
super(ApiNotFoundError, self).__init__(404, url)


if __name__ == '__main__':
import doctest
Expand Down

0 comments on commit 573d107

Please sign in to comment.