from utils import exceptions from api import app from users import blueprint as users_blueprint from external_api import blueprint as external_api_blueprint from projects import blueprint as projects_blueprint from media_plan import blueprint as media_plan_blueprint from core import blueprint as core_blueprint from campaigns import blueprint as campaigns_blueprint from artists import blueprint as artists_blueprint from global_search import blueprint as global_search_blueprint from campaign_ads import blueprint as campaign_ads_blueprint from reporting import blueprint as reporting_blueprint import rq_dashboard from db import db # noqa from models import * # noqa from basic_analytics import blueprint as basic_analytics_blueprint from playlists import blueprint as playlists_blueprint from performance import blueprint as performance_blueprint from artists_moments import blueprint as artists_moments_blueprint from purchase_orders import blueprint as purchase_orders_blueprint from linkfire import blueprint as linkfire_blueprint from data_health import blueprint as data_health_blueprint from labels import blueprint as labels_blueprint from connectors import blueprint as connectors_blueprint from werkzeug.exceptions import UnprocessableEntity from constants import http_status from config import DOCUMENTATION app.register_blueprint(external_api_blueprint) app.register_blueprint(projects_blueprint) app.register_blueprint(media_plan_blueprint) app.register_blueprint(core_blueprint) app.register_blueprint(users_blueprint) app.register_blueprint(basic_analytics_blueprint) app.register_blueprint(campaigns_blueprint) app.register_blueprint(artists_blueprint) app.register_blueprint(playlists_blueprint) app.register_blueprint(global_search_blueprint) app.register_blueprint(campaign_ads_blueprint) app.register_blueprint(performance_blueprint) app.register_blueprint(reporting_blueprint) app.register_blueprint(artists_moments_blueprint) app.register_blueprint(purchase_orders_blueprint) app.register_blueprint(linkfire_blueprint) app.register_blueprint(data_health_blueprint) app.register_blueprint(labels_blueprint) app.register_blueprint(connectors_blueprint) if app.debug: app.register_blueprint(rq_dashboard.blueprint, url_prefix="/rq") if DOCUMENTATION: from swagger import swagger swagger() @app.errorhandler(exceptions.RequestError) def handle_request_error(error): """Handle request and validation errors. Args: error (exceptions.RequestError): Error. """ response = exceptions.ErrorResponse(code=error.error_code, message=error.message) return response, error.status @app.errorhandler(UnprocessableEntity) def handle_validation_error(error): """Handle validation errors. Args: error (UnprocessableEntity): Error. """ try: message = error.data['messages']['json'] except: message = error.data['messages']['query'] response = exceptions.ErrorResponse(code='unprocessable_entity', message=message) return response, http_status.HTTP_422_UNPROCESSABLE_ENTITY