Coverage for yaptide/routes/utils/response_templates.py: 82%

11 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-22 07:31 +0000

1from flask import Response, make_response 

2import html 

3 

4 

5def yaptide_response(message: str, code: int, content: dict = None) -> Response: 

6 """Function returning Response object""" 

7 response_dict = {'message': html.escape(message)} 

8 if content: 

9 response_dict.update(content) 

10 return make_response(response_dict, code) 

11 

12 

13def error_validation_response(content: dict = None) -> Response: 

14 """Function returning Response object when ValidationError occures""" 

15 return yaptide_response(message='Wrong data provided', code=400, content=content) 

16 

17 

18def error_internal_response(content: dict = None) -> Response: 

19 """Function returning Response object when Exception occures""" 

20 return yaptide_response(message='Internal server error', code=500, content=content)