Coverage for demo_server/api/restplus.py: 58%

17 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 15:36 +0000

1# Copyright (c) Microsoft Corporation. 

2# Licensed under the MIT License. 

3 

4import logging 1a

5import traceback 1a

6 

7from flask_restplus import Api 1a

8from demo_server import settings 1a

9from sqlalchemy.orm.exc import NoResultFound 1a

10 

11log = logging.getLogger(__name__) 1a

12 

13api = Api(version='1.0', title='My Blog API', 1a

14 description='A simple demonstration of a Flask RestPlus powered API') 

15 

16 

17@api.errorhandler 1a

18def default_error_handler(e): 1a

19 message = 'An unhandled exception occurred.' 

20 log.exception(message) 

21 

22 if not settings.FLASK_DEBUG: 

23 return {'message': message}, 500 

24 

25 

26@api.errorhandler(NoResultFound) 1a

27def database_not_found_error_handler(e): 1a

28 log.warning(traceback.format_exc()) 

29 return {'message': 'A database result was required but none was found.'}, 404