Skip to content
This repository has been archived by the owner on May 25, 2020. It is now read-only.

Commit

Permalink
Added catch for when an invalid request is entered
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Zharichenko committed Feb 13, 2017
1 parent 08ba07e commit 6bea977
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions apiwrapper/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
CORS(api_wrapper)


@api_wrapper.errorhandler(404)
def page_not_found(e):
return jsonify({'error': 'invalid request'})


@api_wrapper.route('/')
def index():
di = {'status': 'Up! Good work team'}
Expand All @@ -26,36 +31,36 @@ def get_courses(term=None, code=None):


@api_wrapper.route('/class_description/<class_number>/<term>', strict_slashes=False)
def get_class_description(class_number='-1', term='-1'):
if term == '-1' or class_number == '-1':
def get_class_description(class_number=None, term=None):
if term is None or class_number is None:
raise ValueError()

return jsonify(course.get_class_description(class_number, term))


@api_wrapper.route('/lab_status/<lab_name>', strict_slashes=False)
def get_lab_status(lab_name='-1'):
if lab_name == '-1':
def get_lab_status(lab_name=None):
if lab_name is None:
raise ValueError()

return jsonify(lab.get_status(lab_name))


@api_wrapper.route('/laundry_simple/<loc>', strict_slashes=False)
def get_laundry_status_simple(loc='-1'):
if loc == '-1':
def get_laundry_status_simple(loc=None):
if loc is None:
raise ValueError()

return jsonify(laundry.get_status_simple(loc))


@api_wrapper.route('/laundry_detailed/<loc>', strict_slashes=False)
def get_laundry_status_detailed(loc='-1'):
if loc == '-1':
def get_laundry_status_detailed(loc=None):
if loc is None:
raise ValueError()

return jsonify(laundry.get_status_detailed(loc))


if __name__ == '__main__':
if __name__ is '__main__':
api_wrapper.run(debug=True, port=8000)

0 comments on commit 6bea977

Please sign in to comment.