handle exceptions
This commit is contained in:
@@ -4,6 +4,7 @@ import threading
|
||||
import requests
|
||||
from flask import jsonify, request
|
||||
|
||||
from models.exceptions.ServiceException import ServiceException
|
||||
from services.game_service import GameService
|
||||
|
||||
class GameController:
|
||||
@@ -16,7 +17,6 @@ class GameController:
|
||||
self._game_service = GameService()
|
||||
self._register_routes(app)
|
||||
self._auth_token = "0eed89e8-7625-4f8d-bf2a-0872aede0efb"
|
||||
self._has_started = False
|
||||
|
||||
def _register_routes(self, app):
|
||||
app.add_url_rule("/command/party/start", view_func=self.start_party, methods=['POST'])
|
||||
@@ -36,15 +36,15 @@ class GameController:
|
||||
self._game_service.start(white_name, black_name, time_control, increment)
|
||||
self._has_started = True
|
||||
return jsonify({"status": "ok", "message": "Game started"}), 200
|
||||
|
||||
except ServiceException as ex:
|
||||
return jsonify({"status": "error", "message": f"An error occurred : {ex}"}), 400
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
return jsonify({"status": "error", "message": f"An error occurred : {ex}"}), 500
|
||||
|
||||
def make_move(self):
|
||||
try:
|
||||
if not self._has_started:
|
||||
return jsonify({"status": "error", "message": "Game hasn't started yet"}), 400
|
||||
|
||||
auth_token = request.headers.get("Authorization")
|
||||
if auth_token != "Bearer " + self._auth_token:
|
||||
return jsonify({"status": "error", "message": "Invalid authorization token"}), 401
|
||||
@@ -55,6 +55,9 @@ class GameController:
|
||||
).start()
|
||||
|
||||
return jsonify({"status": "ok"}), 200
|
||||
|
||||
except ServiceException as ex:
|
||||
return jsonify({"status": "error", "message": f"An error occurred : {ex}"}), 400
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
return jsonify({"status": "error", "message": f"An error occurred : {ex}"}), 500
|
||||
|
||||
Reference in New Issue
Block a user