Skip to content

Commit

Permalink
initial commit improving logging
Browse files Browse the repository at this point in the history
  • Loading branch information
JackLewis-digirati committed Jan 5, 2024
1 parent 736afa5 commit 4a6b262
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions appetiser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import subprocess

from app.json_utils import (
extract_process_kwargs,
extract_response_items,
Expand Down Expand Up @@ -29,6 +31,7 @@

appetiser = flask.Flask(__name__)


# Import after setup of logging to allow inclusion of
# initialisation logging in wsgi stdout.

Expand All @@ -50,14 +53,34 @@ def ping():
def convert():
json_data = flask.request.get_json()
appetiser.logger.info('Processing request data: %s', json_data)
result = process(**extract_process_kwargs(json_data))
proto_reponse = {
**result,
**extract_response_items(json_data)
}
response = add_iiif_info_json(proto_reponse)
appetiser.logger.info('Response: %s', json_data)
return flask.jsonify(response)
try:
result = process(**extract_process_kwargs(json_data))
proto_reponse = {
**result,
**extract_response_items(json_data)
}
response = add_iiif_info_json(proto_reponse)
appetiser.logger.info('Response: %s', json_data)
return flask.jsonify(response)
except FileNotFoundError as fileError:
appetiser.logger.exception('Error: %s', fileError)
return flask.jsonify(
status='file not found',
message=str(fileError)
), 400
except subprocess.CalledProcessError as subprocess_error:
appetiser.logger.exception('Error: %s', subprocess_error.stderr)
return flask.jsonify(
status='kakadu error',
message=str(subprocess_error.stderr)
), 500
except Exception as general_error:
appetiser.logger.exception('Error: %s', general_error)

return flask.jsonify(
status='server error',
message=str(general_error)
), 500


if __name__ == '__main__':
Expand Down

0 comments on commit 4a6b262

Please sign in to comment.