def wrapper(*args, **kwargs): if request.method == 'GET': #logging.info(f'[decorater - geom]: Getting area by GET {request}') geojson = request.args.get('geojson') if not geojson: return error(status=400, detail='geojson is required') elif request.method == 'POST': geojson = request.get_json().get( 'geojson', None) if request.get_json() else None try: area_ha = AreaService.tabulate_area(geojson) except Exception as e: return error(status=500, detail=str(e)) kwargs["geojson"] = geojson kwargs['area_ha'] = area_ha return func(*args, **kwargs)
def wrapper(*args, **kwargs): if request.method == 'GET': geostore = request.args.get('geostore') if not geostore: return error(status=400, detail='Geostore is required') try: geojson, area_ha = GeostoreService.get(geostore) except GeostoreNotFound: return error(status=404, detail='Geostore not found') elif request.method == 'POST': geojson = request.get_json().get( 'geojson', None) if request.get_json() else None try: area_ha = AreaService.tabulate_area(geojson) except Exception as e: logging.info(f"[middleware geo hash] Exception") return error(status=500, detail=str(e)) kwargs["geojson"] = geojson kwargs["area_ha"] = area_ha return func(*args, **kwargs)
def analyze(geojson, area_ha): """Call Geodescriber""" try: app = request.args.get('app', 'geodescriber') lang = request.args.get('lang', 'en') template = request.args.get('template', '').lower() in ['t', 'true'] gd_result = GeodescriberService.analyze(geojson=geojson, area_ha=area_ha, app=app, lang=lang, template=template) logging.info(f'[Geodescriber ROUTER]: result {gd_result}') return serialize_geodescriber(analysis=gd_result, type='geodescriber'), 200 except GeodescriberError as e: logging.error(f'[Geodescriber ROUTER]: {e.message}') return error(status=500, detail=e.message) except Exception as e: logging.error(f'[Geodescriber ROUTER]: {e}') return error(status=500, detail='Generic Error')
def internal_server_error(e): return error(status=500, detail='Internal Server Error')
def gone(e): return error(status=410, detail='Gone')
def method_not_allowed(e): return error(status=405, detail='Method Not Allowed')
def page_not_found(e): return error(status=404, detail='Not Found')
def forbidden(e): return error(status=403, detail='Forbidden')
def wrapper(*args, **kwargs): if request.method == 'GET': geostore = request.args.get('geostore') if not geostore: return error(status=400, detail='Geostore is required') return func(*args, **kwargs)