From 7ffd57d29464f35ae238f2c38c5b2802cb6c2cb2 Mon Sep 17 00:00:00 2001 From: Daniele Esposti Date: Wed, 22 Feb 2023 22:47:41 +0000 Subject: [PATCH 1/3] Extend the UnexpectedStatus exception to include the response's content --- .../api/default/get_common_parameters.py | 2 +- .../api/default/post_common_parameters.py | 2 +- .../api/location/get_location_header_types.py | 2 +- .../api/location/get_location_query_optionality.py | 2 +- .../get_parameter_references_path_param.py | 2 +- .../delete_common_parameters_overriding_param.py | 2 +- .../parameters/get_common_parameters_overriding_param.py | 2 +- .../parameters/get_same_name_multiple_locations_param.py | 2 +- .../api/parameters/multiple_path_parameters.py | 2 +- .../post_responses_unions_simple_before_complex.py | 2 +- .../my_test_api_client/api/tag1/get_tag_with_number.py | 2 +- .../my_test_api_client/api/tests/callback_test.py | 2 +- .../api/tests/defaults_tests_defaults_post.py | 2 +- .../api/tests/get_basic_list_of_booleans.py | 2 +- .../api/tests/get_basic_list_of_floats.py | 2 +- .../api/tests/get_basic_list_of_integers.py | 2 +- .../api/tests/get_basic_list_of_strings.py | 2 +- .../my_test_api_client/api/tests/get_user_list.py | 2 +- .../api/tests/int_enum_tests_int_enum_post.py | 2 +- .../api/tests/json_body_tests_json_body_post.py | 2 +- .../api/tests/no_response_tests_no_response_get.py | 2 +- .../api/tests/octet_stream_tests_octet_stream_get.py | 2 +- .../my_test_api_client/api/tests/post_form_data.py | 2 +- .../my_test_api_client/api/tests/post_form_data_inline.py | 2 +- .../api/tests/post_tests_json_body_string.py | 2 +- .../my_test_api_client/api/tests/test_inline_objects.py | 2 +- .../tests/token_with_cookie_auth_token_with_cookie_get.py | 2 +- .../unsupported_content_tests_unsupported_content_get.py | 2 +- .../api/tests/upload_file_tests_upload_post.py | 2 +- .../api/tests/upload_multiple_files_tests_upload_post.py | 2 +- .../golden-record/my_test_api_client/api/true_/false_.py | 2 +- .../golden-record/my_test_api_client/errors.py | 6 +++++- .../integration_tests/api/body/post_body_multipart.py | 2 +- .../api/parameters/post_parameters_header.py | 2 +- integration-tests/integration_tests/errors.py | 6 +++++- openapi_python_client/templates/endpoint_module.py.jinja | 3 +-- openapi_python_client/templates/errors.py.jinja | 7 ++++++- 37 files changed, 50 insertions(+), 38 deletions(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py index eea2a39cb..b63f17aa4 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py @@ -37,7 +37,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py index 54f11f8dc..64342b812 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py @@ -37,7 +37,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py index ab6ae3180..19f772674 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py @@ -56,7 +56,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py index 427cf04dc..ce74cdf61 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py @@ -61,7 +61,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py index bdb518de5..b273e6313 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py @@ -47,7 +47,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py index 6ddea0265..60d812c53 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py @@ -38,7 +38,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py index 2089e9c59..8c77dcd3c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py @@ -38,7 +38,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py index c6e0f4736..c1c181c10 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py @@ -46,7 +46,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py index a005a85ac..40983a7d8 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py @@ -36,7 +36,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py b/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py index 811633348..564a80418 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py @@ -37,7 +37,7 @@ def _parse_response( return response_200 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py index 5df86a828..cc50bdc23 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py @@ -30,7 +30,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py index ca87484c4..604adb312 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py @@ -41,7 +41,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return response_422 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py index 44a2cc859..7646cf00c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py @@ -108,7 +108,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return response_422 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py index ce71633d9..bcdf2a727 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py @@ -32,7 +32,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Lis return response_200 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py index dcb97ade5..c2f16ca9a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py @@ -32,7 +32,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Lis return response_200 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py index 800c29608..3dcd48400 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py @@ -32,7 +32,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Lis return response_200 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py index 2a84b2b5e..7a3ba7934 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py @@ -32,7 +32,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Lis return response_200 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py index 6cffd7741..7c83fcde2 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py @@ -91,7 +91,7 @@ def _parse_response( return response_423 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py index 4e23476f5..66ccd3e29 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py @@ -46,7 +46,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return response_422 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py index 383522958..ba24fc1b0 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py @@ -41,7 +41,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return response_422 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py index 933184d3f..72ab545ea 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py @@ -30,7 +30,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py index 99859332e..580bc7076 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py @@ -33,7 +33,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Fil return response_200 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py index ff9e887f4..ca9eb259b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py @@ -33,7 +33,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py index 46536a27a..b0cc33482 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py @@ -33,7 +33,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py index 6a1d178dc..b16b8e3af 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py @@ -40,7 +40,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return response_422 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py index d1533c0e1..cd37fd0b3 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py @@ -38,7 +38,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Tes return response_200 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py index 85d53d9da..25ebef261 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py @@ -35,7 +35,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.UNAUTHORIZED: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py index 2daec1319..6a7364788 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py @@ -30,7 +30,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py index d00ec5e40..4a26740d7 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py @@ -41,7 +41,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return response_422 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py index 34add0e4e..36f510f2f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py @@ -44,7 +44,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return response_422 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py index f8332a87a..bbc13fa70 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py @@ -37,7 +37,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/end_to_end_tests/golden-record/my_test_api_client/errors.py b/end_to_end_tests/golden-record/my_test_api_client/errors.py index a508e1360..043b81285 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/errors.py +++ b/end_to_end_tests/golden-record/my_test_api_client/errors.py @@ -4,7 +4,11 @@ class UnexpectedStatus(Exception): """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True""" - ... + def __init__(self, status_code: int, content: bytes): + self.status_code = status_code + self.content = content + + super().__init__(f"Unexpected status: {status_code}") __all__ = ["UnexpectedStatus"] diff --git a/integration-tests/integration_tests/api/body/post_body_multipart.py b/integration-tests/integration_tests/api/body/post_body_multipart.py index 303443af7..414e7555f 100644 --- a/integration-tests/integration_tests/api/body/post_body_multipart.py +++ b/integration-tests/integration_tests/api/body/post_body_multipart.py @@ -45,7 +45,7 @@ def _parse_response( return response_400 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/integration-tests/integration_tests/api/parameters/post_parameters_header.py b/integration-tests/integration_tests/api/parameters/post_parameters_header.py index c89c4c304..61408f8c6 100644 --- a/integration-tests/integration_tests/api/parameters/post_parameters_header.py +++ b/integration-tests/integration_tests/api/parameters/post_parameters_header.py @@ -52,7 +52,7 @@ def _parse_response( return response_400 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None diff --git a/integration-tests/integration_tests/errors.py b/integration-tests/integration_tests/errors.py index a508e1360..043b81285 100644 --- a/integration-tests/integration_tests/errors.py +++ b/integration-tests/integration_tests/errors.py @@ -4,7 +4,11 @@ class UnexpectedStatus(Exception): """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True""" - ... + def __init__(self, status_code: int, content: bytes): + self.status_code = status_code + self.content = content + + super().__init__(f"Unexpected status: {status_code}") __all__ = ["UnexpectedStatus"] diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index 26d313f16..cdcd2467a 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -74,7 +74,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[{{ {% endif %} {% endfor %} if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None @@ -141,4 +141,3 @@ async def asyncio( {{ kwargs(endpoint) }} )).parsed {% endif %} - diff --git a/openapi_python_client/templates/errors.py.jinja b/openapi_python_client/templates/errors.py.jinja index 7445a2dad..dc879bb6c 100644 --- a/openapi_python_client/templates/errors.py.jinja +++ b/openapi_python_client/templates/errors.py.jinja @@ -2,6 +2,11 @@ class UnexpectedStatus(Exception): """ Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True """ - ... + + def __init__(self, status_code: int, content: bytes): + self.status_code = status_code + self.content = content + + super().__init__(f"Unexpected status: {status_code}") __all__ = ["UnexpectedStatus"] From 17ce715d9d28c07e2a4771b969b537385877111a Mon Sep 17 00:00:00 2001 From: Daniele Esposti Date: Mon, 20 Mar 2023 22:42:19 +0000 Subject: [PATCH 2/3] Updated text in exception --- end_to_end_tests/golden-record/my_test_api_client/errors.py | 2 +- integration-tests/integration_tests/errors.py | 2 +- openapi_python_client/templates/errors.py.jinja | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/errors.py b/end_to_end_tests/golden-record/my_test_api_client/errors.py index 043b81285..426f8a2ed 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/errors.py +++ b/end_to_end_tests/golden-record/my_test_api_client/errors.py @@ -8,7 +8,7 @@ def __init__(self, status_code: int, content: bytes): self.status_code = status_code self.content = content - super().__init__(f"Unexpected status: {status_code}") + super().__init__(f"Unexpected status code: {status_code}") __all__ = ["UnexpectedStatus"] diff --git a/integration-tests/integration_tests/errors.py b/integration-tests/integration_tests/errors.py index 043b81285..426f8a2ed 100644 --- a/integration-tests/integration_tests/errors.py +++ b/integration-tests/integration_tests/errors.py @@ -8,7 +8,7 @@ def __init__(self, status_code: int, content: bytes): self.status_code = status_code self.content = content - super().__init__(f"Unexpected status: {status_code}") + super().__init__(f"Unexpected status code: {status_code}") __all__ = ["UnexpectedStatus"] diff --git a/openapi_python_client/templates/errors.py.jinja b/openapi_python_client/templates/errors.py.jinja index dc879bb6c..514d3c1b9 100644 --- a/openapi_python_client/templates/errors.py.jinja +++ b/openapi_python_client/templates/errors.py.jinja @@ -7,6 +7,6 @@ class UnexpectedStatus(Exception): self.status_code = status_code self.content = content - super().__init__(f"Unexpected status: {status_code}") + super().__init__(f"Unexpected status code: {status_code}") __all__ = ["UnexpectedStatus"] From 44dee219434fad07f9b34b605cae0969d675432c Mon Sep 17 00:00:00 2001 From: Daniele Esposti Date: Mon, 20 Mar 2023 23:03:54 +0000 Subject: [PATCH 3/3] Fixed issue after merging from default branch --- .../my_test_api_client/api/tests/description_with_backslash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py index db605c979..b62ed2a6a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py @@ -30,7 +30,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None