mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Fixes API return HTTP return types and messages
This commit is contained in:
@@ -5,6 +5,7 @@ LOCATOR_LEN_BYTES = LOCATOR_LEN_HEX // 2
|
||||
# HTTP
|
||||
HTTP_OK = 200
|
||||
HTTP_BAD_REQUEST = 400
|
||||
HTTP_NOT_FOUND = 404
|
||||
HTTP_SERVICE_UNAVAILABLE = 503
|
||||
|
||||
# Temporary constants, may be changed
|
||||
|
||||
20
teos/api.py
20
teos/api.py
@@ -10,7 +10,13 @@ from teos.gatekeeper import NotEnoughSlots, IdentificationFailure
|
||||
|
||||
from common.logger import Logger
|
||||
from common.cryptographer import hash_160
|
||||
from common.constants import HTTP_OK, HTTP_BAD_REQUEST, HTTP_SERVICE_UNAVAILABLE, ENCRYPTED_BLOB_MAX_SIZE_HEX
|
||||
from common.constants import (
|
||||
HTTP_OK,
|
||||
HTTP_BAD_REQUEST,
|
||||
HTTP_SERVICE_UNAVAILABLE,
|
||||
HTTP_NOT_FOUND,
|
||||
ENCRYPTED_BLOB_MAX_SIZE_HEX,
|
||||
)
|
||||
|
||||
|
||||
# ToDo: #5-add-async-to-api
|
||||
@@ -162,11 +168,11 @@ class API:
|
||||
error = "appointment rejected. Error {}: {}".format(e.erno, e.reason)
|
||||
response = {"error": error}
|
||||
|
||||
except (IdentificationFailure, NotEnoughSlots) as e:
|
||||
except (IdentificationFailure, NotEnoughSlots):
|
||||
rcode = HTTP_BAD_REQUEST
|
||||
error = "appointment rejected. Error {}: {}".format(
|
||||
errors.APPOINTMENT_INVALID_SIGNATURE_OR_INSUFFICIENT_SLOTS,
|
||||
"Invalid signature or the user does not have enough slots available",
|
||||
"Invalid signature or user does not have enough slots available",
|
||||
)
|
||||
response = {"error": error}
|
||||
|
||||
@@ -219,24 +225,26 @@ class API:
|
||||
if uuid in triggered_appointments:
|
||||
response = self.watcher.db_manager.load_responder_tracker(uuid)
|
||||
if response:
|
||||
rcode = HTTP_OK
|
||||
response["status"] = "dispute_responded"
|
||||
else:
|
||||
rcode = HTTP_NOT_FOUND
|
||||
response = {"locator": locator, "status": "not_found"}
|
||||
|
||||
# Otherwise it should be either in the watcher, or not in the system.
|
||||
else:
|
||||
response = self.watcher.db_manager.load_watcher_appointment(uuid)
|
||||
if response:
|
||||
rcode = HTTP_OK
|
||||
response["status"] = "being_watched"
|
||||
else:
|
||||
rcode = HTTP_NOT_FOUND
|
||||
response = {"locator": locator, "status": "not_found"}
|
||||
|
||||
except (InspectionFailed, IdentificationFailure):
|
||||
rcode = HTTP_NOT_FOUND
|
||||
response = {"locator": locator, "status": "not_found"}
|
||||
|
||||
finally:
|
||||
rcode = HTTP_OK
|
||||
|
||||
else:
|
||||
rcode = HTTP_BAD_REQUEST
|
||||
error = "appointment rejected. Request is not json encoded"
|
||||
|
||||
Reference in New Issue
Block a user