Skip to content

Commit

Permalink
feat: Add pointer details to error log
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed May 3, 2024
1 parent e75b030 commit 3527730
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions polarion_rest_api_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ def __init__(
add_work_item_checksum: bool = False,
max_content_size: int = ...,
httpx_args: t.Optional[dict[str, t.Any]] = ...,
):
...
): ...

@t.overload
def __init__(
Expand All @@ -116,8 +115,7 @@ def __init__(
add_work_item_checksum: bool = False,
max_content_size: int = ...,
httpx_args: t.Optional[dict[str, t.Any]] = ...,
):
...
): ...

def __init__(
self,
Expand Down Expand Up @@ -222,7 +220,18 @@ def filter_none_values(data: dict[str, t.Any]):
error = api_models.Errors.from_dict(decoded_content)
if error.errors:
raise errors.PolarionApiException(
*[(e.status, e.detail) for e in error.errors]
*[
(
e.status,
e.detail,
(
e.source.pointer
if not isinstance(e.source, oa_types.Unset)
else "No error pointer"
),
)
for e in error.errors
]
)
raise unexpected_error()

Expand All @@ -249,9 +258,9 @@ def _build_work_item_post_request(
attrs.additional_properties.update(work_item.additional_attributes)

if self.add_work_item_checksum:
attrs.additional_properties[
"checksum"
] = work_item.calculate_checksum()
attrs.additional_properties["checksum"] = (
work_item.calculate_checksum()
)

return api_models.WorkitemsListPostRequestDataItem(
api_models.WorkitemsListPostRequestDataItemType.WORKITEMS, attrs
Expand Down Expand Up @@ -279,9 +288,9 @@ def _build_work_item_patch_request(
attrs.additional_properties.update(work_item.additional_attributes)

if self.add_work_item_checksum:
attrs.additional_properties[
"checksum"
] = work_item.get_current_checksum()
attrs.additional_properties["checksum"] = (
work_item.get_current_checksum()
)

return api_models.WorkitemsSinglePatchRequest(
api_models.WorkitemsSinglePatchRequestData(
Expand Down Expand Up @@ -525,9 +534,9 @@ def create_work_item_attachments(
counter = 0
for work_item_attachment_res in response.parsed.data:
assert work_item_attachment_res.id
work_item_attachments[
counter
].id = work_item_attachment_res.id.split("/")[-1]
work_item_attachments[counter].id = (
work_item_attachment_res.id.split("/")[-1]
)
counter += 1

def get_work_items(
Expand Down Expand Up @@ -624,8 +633,10 @@ def get_work_item(

def _generate_work_item(
self,
work_item: api_models.WorkitemsListGetResponseDataItem
| api_models.WorkitemsSingleGetResponseData,
work_item: (
api_models.WorkitemsListGetResponseDataItem
| api_models.WorkitemsSingleGetResponseData
),
) -> base_client.WorkItemType:
assert work_item.attributes
assert isinstance(work_item.id, str)
Expand Down Expand Up @@ -756,8 +767,10 @@ def get_document(

def _handle_home_page_content(
self,
home_page_content: api_models.DocumentsSingleGetResponseDataAttributesHomePageContent
| oa_types.Unset,
home_page_content: (
api_models.DocumentsSingleGetResponseDataAttributesHomePageContent
| oa_types.Unset
),
) -> dm.TextContent | None:
if isinstance(home_page_content, oa_types.Unset):
return None
Expand Down

0 comments on commit 3527730

Please sign in to comment.