Total Complexity | 5 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from flask import Blueprint, g |
||
2 | from ..errors import ValidationError, bad_request, not_found |
||
3 | |||
4 | |||
5 | api = Blueprint('api', __name__) |
||
6 | |||
7 | |||
8 | @api.errorhandler(ValidationError) |
||
9 | def validation_error(e): |
||
10 | return bad_request(e.args[0]) |
||
11 | |||
12 | |||
13 | @api.errorhandler(400) |
||
14 | def bad_request_error(e): |
||
15 | return bad_request('invalid request') |
||
16 | |||
17 | |||
18 | @api.errorhandler(404) |
||
19 | def not_found_error(e): |
||
20 | return not_found('item not found') |
||
21 | |||
22 | |||
23 | @api.after_request |
||
24 | def after_request(response): |
||
25 | if hasattr(g, 'headers'): |
||
26 | response.headers.extend(g.headers) |
||
27 | return response |
||
28 | |||
29 | # do this last to avoid circular dependencies |
||
30 | from . import todos |
||
31 |