Skip to content

Commit f3d7d73

Browse files
committed
Contrib handlers refactor
1 parent 1f94be4 commit f3d7d73

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

openapi_core/contrib/falcon/handlers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def handle(cls, req, resp, errors):
3939
'errors': data_errors,
4040
}
4141
data_str = dumps(data)
42-
data_error_max = max(data_errors, key=lambda x: x['status'])
42+
data_error_max = max(data_errors, key=cls.get_error_status)
4343
resp.content_type = MEDIA_JSON
4444
resp.status = cls.FALCON_STATUS_CODES.get(
4545
data_error_max['status'], HTTP_400)
@@ -53,3 +53,7 @@ def format_openapi_error(cls, error):
5353
'status': cls.OPENAPI_ERROR_STATUS.get(error.__class__, 400),
5454
'class': str(type(error)),
5555
}
56+
57+
@classmethod
58+
def get_error_status(cls, error):
59+
return error['status']

openapi_core/contrib/flask/handlers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def handle(cls, errors):
2626
data = {
2727
'errors': data_errors,
2828
}
29-
data_error_max = max(data_errors, key=lambda x: x['status'])
29+
data_error_max = max(data_errors, key=cls.get_error_status)
3030
status = data_error_max['status']
3131
return current_app.response_class(
3232
dumps(data),
@@ -41,3 +41,7 @@ def format_openapi_error(cls, error):
4141
'status': cls.OPENAPI_ERROR_STATUS.get(error.__class__, 400),
4242
'class': str(type(error)),
4343
}
44+
45+
@classmethod
46+
def get_error_status(cls, error):
47+
return error['status']

0 commit comments

Comments
 (0)