Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Merge a3007f6 into eb71152
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Francisco committed Jul 6, 2020
2 parents eb71152 + a3007f6 commit b34b4c0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions kytos/core/api_server.py
Expand Up @@ -15,6 +15,7 @@
from flask import Flask, jsonify, request, send_file
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, leave_room
from werkzeug.exceptions import HTTPException


class APIServer:
Expand Down Expand Up @@ -61,6 +62,22 @@ def __init__(self, app_name, listen='0.0.0.0', port=8181,
# Update web-ui if necessary
self.update_web_ui(force=False)

@self.app.errorhandler(HTTPException)
def handle_exception(e):
# pylint: disable=unused-variable, invalid-name
"""Return a json for HTTP errors
This handler allows NApps to return HTTP error messages
by raising a HTTPException. When raising the Exception,
create it with a description.
"""
response = jsonify({
'code': e.code,
'name': e.name,
'description': e.description
})
return response, e.code

def _enable_websocket_rooms(self):
socket = self.server
socket.on_event('join', join_room)
Expand Down

0 comments on commit b34b4c0

Please sign in to comment.