Skip to content

Commit

Permalink
更新 change.log
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-smile committed Nov 20, 2023
1 parent fdf0826 commit 3c9fde1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
6 changes: 6 additions & 0 deletions sdks/bkapi-client-core/CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Change logs

## 1.2.0
- BK_API_CLIENT_ENABLE_SSL_VERIFY 默认值设置为 False
- BaseClient 处理响应内容时优先检查 json,添加辅助方法:check_response_apigateway_error, check_response_status
- ResponseError 添加 response_status_code/response_text/response_json 等辅助方法
- 日志中,curl 信息中不再携带请求头

### 1.1.8
- 使用 `CurlRequest` 封装转换 curl 命令的逻辑以优化性能

Expand Down
2 changes: 1 addition & 1 deletion sdks/bkapi-client-core/bkapi_client_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
"""
__version__ = "1.1.9"
__version__ = "1.2.0"
4 changes: 2 additions & 2 deletions sdks/bkapi-client-core/bkapi_client_core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,10 @@ def _handle_exception(
# log exception
if isinstance(exception, RequestException):
response = exception.response
response_headers_representer = ResponseHeadersRepresenter(response and response.headers)
response_headers_representer = ResponseHeadersRepresenter(response.headers if response is not None else None)
logger.warning(
"request bkapi failed. status_code: %s, %s\n%s",
response and response.status_code,
response.status_code if response is not None else None,
response_headers_representer,
CurlRequest(exception.request),
)
Expand Down
14 changes: 6 additions & 8 deletions sdks/bkapi-client-core/bkapi_client_core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ def request_url(self):
@property
def response_status_code(self):
# type: (...) -> Optional[int]
return self.response and self.response.status_code
# bool(response) is equal to response.ok
return self.response.status_code if self.response is not None else None

@property
def response_text(self):
# type: (...) -> Optional[str]
try:
return self.response and self.response.text
except Exception:
return None
return self.response.text if self.response is not None else None

def response_json(self):
return self.response.json() if self.response is not None else None

def __str__(self):
if self.response is None:
Expand All @@ -127,9 +128,6 @@ class APIGatewayResponseError(ResponseError):
class HTTPResponseError(ResponseError):
"""HTTP request status code error"""

def response_json(self):
return self.response.json()


class JSONResponseError(ResponseError):
"""The response content is not a valid json"""
Expand Down
2 changes: 1 addition & 1 deletion sdks/bkapi-client-core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bkapi-client-core"
version = "1.1.9"
version = "1.2.0"
description = "A toolkit for buiding blueking API clients."
readme = "README.md"
authors = ["blueking <[email protected]>"]
Expand Down
13 changes: 12 additions & 1 deletion sdks/bkapi-client-core/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,23 @@ def test_request_url(self, mocker, faker, request_, expected):
[
(None, None),
({"status_code": 200}, 200),
({"status_code": 400}, 400),
]
)
def test_request_status_code(self, mocker, faker, response, expected):
def test_response_status_code(self, mocker, faker, response, expected):
err = exceptions.ResponseError(
faker.pystr(),
response=response and mocker.MagicMock(**response),
response_headers_representer=ResponseHeadersRepresenter({"X-Bkapi-Request-Id": "abcdef"}),
)
assert err.response_status_code == expected

def test_response_json(self, mocker, faker):
err = exceptions.ResponseError(faker.pystr(), response=None)
assert err.response_json() == None

err = exceptions.ResponseError(
faker.pystr(),
response=mocker.MagicMock(**{"json.return_value": {"foo": "bar"}})
)
assert err.response_json() == {"foo": "bar"}

0 comments on commit 3c9fde1

Please sign in to comment.