-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
51 lines (38 loc) · 1.16 KB
/
application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Module for app factory"""
# System libraries
import os
# Third-party libraries
from flask import Flask, jsonify
# Local imports
from config import app_config
from app import movies
from app.utils import MSG, Helper
# get function reference
create_message = Helper().create_message
def create_app(env_config=None):
"""Instantiate and return flask app"""
app = Flask(__name__)
# configure app object
app.config.from_object(app_config.get(env_config\
or os.getenv('FLASK_ENV')))
# handle unknown url errors
@app.errorhandler(404)
def url_unknown(e):
return jsonify(
create_message(MSG['url_unknown'], error=True)
), 404
# handle Internal Server Errors
@app.errorhandler(500)
def internal_server_error(e):
return jsonify(
create_message(MSG['internal_server_error'], error=True)
), 500
# handle unauthorized method errors
@app.errorhandler(405)
def method_not_allowed(e):
return jsonify(
create_message(MSG['unsupported_action'], error=True)
), 405
# register movies app
app.register_blueprint(movies)
return app