From 0418afbdc50b497fec7359176cd4ceca5649ec6f Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Wed, 14 Nov 2018 13:38:16 +0000 Subject: [PATCH] Made 404 errors more API friendly --- openflexure_microscope/api/v1.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openflexure_microscope/api/v1.py b/openflexure_microscope/api/v1.py index 009435cc..8c50d524 100644 --- a/openflexure_microscope/api/v1.py +++ b/openflexure_microscope/api/v1.py @@ -14,7 +14,8 @@ import datetime from flask import ( Flask, render_template, Response, - redirect, request, jsonify, send_file, abort) + redirect, request, jsonify, send_file, abort, + make_response) import numpy as np @@ -29,6 +30,11 @@ import logging, sys logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +# Make errors more API friendly +@app.errorhandler(404) +def not_found(error): + return make_response(jsonify({'error': 'Not found'}), 404) + # Create the microscope object globally (common to all spawned server threads) microscope = Microscope( StreamingCamera(),