-from optparse import OptionParser
-from osdf.operation.exceptions import BusinessException
-from osdf.operation.error_handling import request_exception_to_json_body, internal_error_message
-from requests import RequestException
-from schematics.exceptions import DataError
-from osdf.logging.osdf_logging import MH, audit_log, error_log, debug_log
-from osdf.models.api.placementRequest import PlacementAPI
-
-ERROR_TEMPLATE = osdf.ERROR_TEMPLATE
-
-app = Flask(__name__)
-
-BAD_CLIENT_REQUEST_MESSAGE = 'Client sent an invalid request'
-
-
-@app.errorhandler(BusinessException)
-def handle_business_exception(e):
- """An exception explicitly raised due to some business rule"""
- error_log.error("Synchronous error for request id {} {}".format(g.request_id, traceback.format_exc()))
- err_msg = ERROR_TEMPLATE.render(description=str(e))
- response = Response(err_msg, content_type='application/json; charset=utf-8')
- response.status_code = 400
- return response
-
-
-@app.errorhandler(RequestException)
-def handle_request_exception(e):
- """Returns a detailed synchronous message to the calling client
- when osdf fails due to a remote call to another system"""
- error_log.error("Synchronous error for request id {} {}".format(g.request_id, traceback.format_exc()))
- err_msg = request_exception_to_json_body(e)
- response = Response(err_msg, content_type='application/json; charset=utf-8')
- response.status_code = 400
- return response
-
-
-@app.errorhandler(DataError)
-def handle_data_error(e):
- """Returns a detailed message to the calling client when the initial synchronous message is invalid"""
- error_log.error("Synchronous error for request id {} {}".format(g.request_id, traceback.format_exc()))
-
- body_dictionary = {
- "serviceException": {
- "text": BAD_CLIENT_REQUEST_MESSAGE,
- "exceptionMessage": str(e.errors),
- "errorType": "InvalidClientRequest"
- }
- }
-
- body_as_json = json.dumps(body_dictionary)
- response = Response(body_as_json, content_type='application/json; charset=utf-8')
- response.status_code = 400
- return response