Skip to content

Commit

Permalink
improve error handling on main
Browse files Browse the repository at this point in the history
  • Loading branch information
maede97 committed Nov 5, 2023
1 parent ce0698b commit 4a342f9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ def parse_route():
result_json['elevation_data'] = path.to_elevation_polyline()

return app.response_class(response=json.dumps(result_json), status=200, mimetype='application/json')

except UserException as e:
logger.error(e)
return app.response_class(response=json.dumps({'status':GeneratorStatus.ERROR, 'message': str(e) }))
except Exception as e:

logger.error('Exception while parsing file: {}'.format(e))

return app.response_class(
response=json.dumps({'status': GeneratorStatus.ERROR, 'message': str(e)}),
status=400, mimetype='application/json')
response=json.dumps({'status': GeneratorStatus.ERROR, 'message': 'Ein Fehler beim Einlesen der Route ist aufgetreten.'}),
status=500, mimetype='application/json')


@app.route('/create-walk-time-table', methods=['POST'])
Expand All @@ -95,7 +95,7 @@ def create_walk_time_table():
options = json.loads(request.form['options'])
else:
return app.response_class(
response=json.dumps({'status': GeneratorStatus.ERROR, 'message': 'Invalid request format.'}),
response=json.dumps({'status': GeneratorStatus.ERROR, 'message': 'Die Optionen fehlen.'}),
status=400, mimetype='application/json')

# Decode options['route'] form polyline
Expand Down Expand Up @@ -137,7 +137,7 @@ def create_walk_time_table():

else:
return app.response_class(
response=json.dumps({'status': GeneratorStatus.ERROR, 'message': 'Invalid Encoding of route.'}),
response=json.dumps({'status': GeneratorStatus.ERROR, 'message': 'Die Route kann leider nicht eingelesen werden.'}),
status=400, mimetype='application/json')
except UserException as e:
logger.error(e)
Expand All @@ -146,7 +146,7 @@ def create_walk_time_table():

except Exception as e:
logger.error(e)
response = json.dumps({'status': GeneratorStatus.ERROR, 'message': str(e)})
response = json.dumps({'status': GeneratorStatus.ERROR, 'message': 'Ein Fehler ist aufgetreten.'})
return app.response_class(response = response, status=500, mimetype="application/json")


Expand Down Expand Up @@ -179,7 +179,7 @@ def create_map():
options = json.loads(request.form['options'])
else:
return app.response_class(
response=json.dumps({'status': GeneratorStatus.ERROR, 'message': 'Invalid request format.'}),
response=json.dumps({'status': GeneratorStatus.ERROR, 'message': 'Die Optionen fehlen.'}),
status=400, mimetype='application/json')

thread = Thread(target=create_export, kwargs={'options': options, 'uuid': uuid})
Expand Down Expand Up @@ -295,7 +295,7 @@ def download(uuid):
return app.response_class(
response=json.dumps({
'status': GeneratorStatus.ERROR,
'message': 'Requested data is not available anymore.'
'message': 'Die angeforderten Daten sind nicht verfügbar.'
}), status=404, mimetype='application/json')

# Return Zip with data
Expand Down

0 comments on commit 4a342f9

Please sign in to comment.