Skip to content

Commit e26e93f

Browse files
james-bigpayJamesHinshelwood
authored andcommitted
feat: Add raise_on_unexpected_status flag to Client
1 parent d8d9cec commit e26e93f

33 files changed

+371
-182
lines changed

end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Union
1+
from typing import Any, Dict, Optional, Union
22

33
import httpx
44

@@ -31,12 +31,22 @@ def _get_kwargs(
3131
}
3232

3333

34-
def _build_response(*, response: httpx.Response) -> Response[Any]:
34+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
35+
if response.status_code == 200:
36+
response_200 = None
37+
return response_200
38+
if client.raise_on_unexpected_status:
39+
raise Exception(f"Unexpected status code: {response.status_code}")
40+
else:
41+
return None
42+
43+
44+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
3545
return Response(
3646
status_code=response.status_code,
3747
content=response.content,
3848
headers=response.headers,
39-
parsed=None,
49+
parsed=_parse_response(client=client, response=response),
4050
)
4151

4252

@@ -63,7 +73,7 @@ def sync_detailed(
6373
**kwargs,
6474
)
6575

66-
return _build_response(response=response)
76+
return _build_response(client=client, response=response)
6777

6878

6979
async def asyncio_detailed(
@@ -87,4 +97,4 @@ async def asyncio_detailed(
8797
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
8898
response = await _client.request(**kwargs)
8999

90-
return _build_response(response=response)
100+
return _build_response(client=client, response=response)

end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Union
1+
from typing import Any, Dict, Optional, Union
22

33
import httpx
44

@@ -31,12 +31,22 @@ def _get_kwargs(
3131
}
3232

3333

34-
def _build_response(*, response: httpx.Response) -> Response[Any]:
34+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
35+
if response.status_code == 200:
36+
response_200 = None
37+
return response_200
38+
if client.raise_on_unexpected_status:
39+
raise Exception(f"Unexpected status code: {response.status_code}")
40+
else:
41+
return None
42+
43+
44+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
3545
return Response(
3646
status_code=response.status_code,
3747
content=response.content,
3848
headers=response.headers,
39-
parsed=None,
49+
parsed=_parse_response(client=client, response=response),
4050
)
4151

4252

@@ -63,7 +73,7 @@ def sync_detailed(
6373
**kwargs,
6474
)
6575

66-
return _build_response(response=response)
76+
return _build_response(client=client, response=response)
6777

6878

6979
async def asyncio_detailed(
@@ -87,4 +97,4 @@ async def asyncio_detailed(
8797
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
8898
response = await _client.request(**kwargs)
8999

90-
return _build_response(response=response)
100+
return _build_response(client=client, response=response)

end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Union
1+
from typing import Any, Dict, Optional, Union
22

33
import httpx
44

@@ -40,12 +40,19 @@ def _get_kwargs(
4040
}
4141

4242

43-
def _build_response(*, response: httpx.Response) -> Response[Any]:
43+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
44+
if client.raise_on_unexpected_status:
45+
raise Exception(f"Unexpected status code: {response.status_code}")
46+
else:
47+
return None
48+
49+
50+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
4451
return Response(
4552
status_code=response.status_code,
4653
content=response.content,
4754
headers=response.headers,
48-
parsed=None,
55+
parsed=_parse_response(client=client, response=response),
4956
)
5057

5158

@@ -81,7 +88,7 @@ def sync_detailed(
8188
**kwargs,
8289
)
8390

84-
return _build_response(response=response)
91+
return _build_response(client=client, response=response)
8592

8693

8794
async def asyncio_detailed(
@@ -114,4 +121,4 @@ async def asyncio_detailed(
114121
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
115122
response = await _client.request(**kwargs)
116123

117-
return _build_response(response=response)
124+
return _build_response(client=client, response=response)

end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime
2-
from typing import Any, Dict, Union
2+
from typing import Any, Dict, Optional, Union
33

44
import httpx
55

@@ -55,12 +55,19 @@ def _get_kwargs(
5555
}
5656

5757

58-
def _build_response(*, response: httpx.Response) -> Response[Any]:
58+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
59+
if client.raise_on_unexpected_status:
60+
raise Exception(f"Unexpected status code: {response.status_code}")
61+
else:
62+
return None
63+
64+
65+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
5966
return Response(
6067
status_code=response.status_code,
6168
content=response.content,
6269
headers=response.headers,
63-
parsed=None,
70+
parsed=_parse_response(client=client, response=response),
6471
)
6572

6673

@@ -96,7 +103,7 @@ def sync_detailed(
96103
**kwargs,
97104
)
98105

99-
return _build_response(response=response)
106+
return _build_response(client=client, response=response)
100107

101108

102109
async def asyncio_detailed(
@@ -129,4 +136,4 @@ async def asyncio_detailed(
129136
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
130137
response = await _client.request(**kwargs)
131138

132-
return _build_response(response=response)
139+
return _build_response(client=client, response=response)

end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Union
1+
from typing import Any, Dict, Optional, Union
22

33
import httpx
44

@@ -32,12 +32,22 @@ def _get_kwargs(
3232
}
3333

3434

35-
def _build_response(*, response: httpx.Response) -> Response[Any]:
35+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
36+
if response.status_code == 200:
37+
response_200 = None
38+
return response_200
39+
if client.raise_on_unexpected_status:
40+
raise Exception(f"Unexpected status code: {response.status_code}")
41+
else:
42+
return None
43+
44+
45+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
3646
return Response(
3747
status_code=response.status_code,
3848
content=response.content,
3949
headers=response.headers,
40-
parsed=None,
50+
parsed=_parse_response(client=client, response=response),
4151
)
4252

4353

@@ -67,7 +77,7 @@ def sync_detailed(
6777
**kwargs,
6878
)
6979

70-
return _build_response(response=response)
80+
return _build_response(client=client, response=response)
7181

7282

7383
async def asyncio_detailed(
@@ -94,4 +104,4 @@ async def asyncio_detailed(
94104
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
95105
response = await _client.request(**kwargs)
96106

97-
return _build_response(response=response)
107+
return _build_response(client=client, response=response)

end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict
1+
from typing import Any, Dict, Optional
22

33
import httpx
44

@@ -32,12 +32,22 @@ def _get_kwargs(
3232
}
3333

3434

35-
def _build_response(*, response: httpx.Response) -> Response[Any]:
35+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
36+
if response.status_code == 200:
37+
response_200 = None
38+
return response_200
39+
if client.raise_on_unexpected_status:
40+
raise Exception(f"Unexpected status code: {response.status_code}")
41+
else:
42+
return None
43+
44+
45+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
3646
return Response(
3747
status_code=response.status_code,
3848
content=response.content,
3949
headers=response.headers,
40-
parsed=None,
50+
parsed=_parse_response(client=client, response=response),
4151
)
4252

4353

@@ -69,7 +79,7 @@ def sync_detailed(
6979
**kwargs,
7080
)
7181

72-
return _build_response(response=response)
82+
return _build_response(client=client, response=response)
7383

7484

7585
async def asyncio_detailed(
@@ -98,4 +108,4 @@ async def asyncio_detailed(
98108
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
99109
response = await _client.request(**kwargs)
100110

101-
return _build_response(response=response)
111+
return _build_response(client=client, response=response)

end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Union
1+
from typing import Any, Dict, Optional, Union
22

33
import httpx
44

@@ -40,12 +40,22 @@ def _get_kwargs(
4040
}
4141

4242

43-
def _build_response(*, response: httpx.Response) -> Response[Any]:
43+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
44+
if response.status_code == 200:
45+
response_200 = None
46+
return response_200
47+
if client.raise_on_unexpected_status:
48+
raise Exception(f"Unexpected status code: {response.status_code}")
49+
else:
50+
return None
51+
52+
53+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
4454
return Response(
4555
status_code=response.status_code,
4656
content=response.content,
4757
headers=response.headers,
48-
parsed=None,
58+
parsed=_parse_response(client=client, response=response),
4959
)
5060

5161

@@ -81,7 +91,7 @@ def sync_detailed(
8191
**kwargs,
8292
)
8393

84-
return _build_response(response=response)
94+
return _build_response(client=client, response=response)
8595

8696

8797
async def asyncio_detailed(
@@ -114,4 +124,4 @@ async def asyncio_detailed(
114124
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
115125
response = await _client.request(**kwargs)
116126

117-
return _build_response(response=response)
127+
return _build_response(client=client, response=response)

end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict
1+
from typing import Any, Dict, Optional
22

33
import httpx
44

@@ -30,12 +30,22 @@ def _get_kwargs(
3030
}
3131

3232

33-
def _build_response(*, response: httpx.Response) -> Response[Any]:
33+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
34+
if response.status_code == 200:
35+
response_200 = None
36+
return response_200
37+
if client.raise_on_unexpected_status:
38+
raise Exception(f"Unexpected status code: {response.status_code}")
39+
else:
40+
return None
41+
42+
43+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
3444
return Response(
3545
status_code=response.status_code,
3646
content=response.content,
3747
headers=response.headers,
38-
parsed=None,
48+
parsed=_parse_response(client=client, response=response),
3949
)
4050

4151

@@ -71,7 +81,7 @@ def sync_detailed(
7181
**kwargs,
7282
)
7383

74-
return _build_response(response=response)
84+
return _build_response(client=client, response=response)
7585

7686

7787
async def asyncio_detailed(
@@ -104,4 +114,4 @@ async def asyncio_detailed(
104114
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
105115
response = await _client.request(**kwargs)
106116

107-
return _build_response(response=response)
117+
return _build_response(client=client, response=response)

0 commit comments

Comments
 (0)