Skip to content

Commit 2112eb4

Browse files
committed
change http status code on error
1 parent c8753f3 commit 2112eb4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

server/api_request_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def handle(self, client_address: tuple, post_data: dict):
2828

2929
response = {
3030
'status': 'error',
31+
'status_code': 400,
3132
'error_message': str(ex)
3233
}
3334
except ExecutionError as ex:
@@ -40,6 +41,7 @@ def handle(self, client_address: tuple, post_data: dict):
4041

4142
response = {
4243
'status': 'error',
44+
'status_code': 500,
4345
'error_message': 'error during execution request'
4446
}
4547

server/proxy_provider_server.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,22 @@ async def post(self, request):
112112
response = _api_request_handler.handle(client_address, data)
113113
except ValueError:
114114
response = {
115-
'status': "error",
115+
'status': 'error',
116+
'status_code': 400,
116117
'error_message': "Your request doesn't look like request",
117118
}
118119

119-
return aiohttp.web.json_response(response)
120+
if 'status_code' in response:
121+
status_code = response['status_code']
122+
else:
123+
if response['status'] != 'ok':
124+
status_code = 500
125+
else:
126+
status_code = 200
127+
128+
response['status_code'] = status_code
129+
130+
return aiohttp.web.json_response(response, status=status_code)
120131

121132
@get_response_wrapper("collector_state.html")
122133
async def get_collector_state_html(self, request):

0 commit comments

Comments
 (0)