From 10005d74d3e40786458f1e92d6de55875374a975 Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Fri, 23 Aug 2019 13:01:28 +0100 Subject: [PATCH] Add 404 and server error handlers --- net-dhcp/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net-dhcp/__init__.py b/net-dhcp/__init__.py index cc11a0a..67345d2 100644 --- a/net-dhcp/__init__.py +++ b/net-dhcp/__init__.py @@ -1,5 +1,13 @@ -from flask import Flask +from flask import Flask, jsonify app = Flask(__name__) -from . import network, ipam \ No newline at end of file +from . import network, ipam + +@app.errorhandler(404) +def err_not_found(e): + return jsonify({'Err': 'API not found'}), 404 + +@app.errorhandler(Exception) +def err(e): + return jsonify({'Err': f'Error: {e}'}), 500