from flask import Flask

from .extensions import envcfg, apierrors, applogging
from .blueprints.status import blueprint as status_bp
from .blueprints.content import blueprint as content_bp
from .blueprints.swagger import blueprint as swagger_bp


def create_app():
    app = Flask('content')
    app.config.from_object('content.default_settings')
    envcfg.init_app(app)
    applogging.init_app(app)
    apierrors.init_app(app)
    app.register_blueprint(status_bp)
    app.register_blueprint(content_bp, url_prefix='/v1')
    app.register_blueprint(swagger_bp)
    return app

from flask import Flask, jsonify

from botocore.exceptions import ClientError

from .extensions import envcfg, apierrors, applogging
from .blueprints.status import blueprint as status_bp
from .blueprints.content import blueprint as content_bp
from .blueprints.swagger import blueprint as swagger_bp


def create_app():
    app = Flask('content')
    app.config.from_object('content.default_settings')
    envcfg.init_app(app)
    applogging.init_app(app)
    apierrors.init_app(app)
    app.register_blueprint(status_bp)
    app.register_blueprint(content_bp, url_prefix='/v1')
    app.register_blueprint(swagger_bp)
    app.register_error_handler(ClientError, _no_such_key)
    return app


def _no_such_key(error):
    # Boto3 exceptions are idiotic.
    if error.response['Error']['Code'] != "NoSuchEntity":
        return jsonify({'error': 'No such content'}), 404
    else:
        raise error

Return 404 when no content found.
Return 404 when no content found.

