mirror of
https://github.com/catspace-dev/unicheckbot.git
synced 2024-11-22 05:46:33 +03:00
added node info in api response
This commit is contained in:
parent
6ab17a0109
commit
f14e4da283
|
@ -1,10 +1,11 @@
|
|||
from core.coretypes import (
|
||||
Response, HttpCheckerResponse,
|
||||
ResponseStatus, HttpErrorCodes, ErrorPayload
|
||||
Response, HttpCheckerResponse, APINodeInfo,
|
||||
ResponseStatus, HttpErrorCodes, ErrorPayload,
|
||||
)
|
||||
from requests import Session
|
||||
from requests.exceptions import ConnectionError
|
||||
from .base import BaseChecker
|
||||
from api.config import NODE_NAME, NODE_LOCATION
|
||||
import time
|
||||
import re
|
||||
|
||||
|
@ -29,12 +30,16 @@ class HttpChecker(BaseChecker):
|
|||
request = self.session.get(
|
||||
url
|
||||
)
|
||||
# TODO: requests.exceptions.InvalidURL failed to parse exception
|
||||
except ConnectionError:
|
||||
return Response(
|
||||
status=ResponseStatus.ERROR,
|
||||
payload=ErrorPayload(
|
||||
message="Failed to establish a new connection",
|
||||
code=HttpErrorCodes.ConnectError
|
||||
code=HttpErrorCodes.ConnectError,
|
||||
),
|
||||
node=APINodeInfo(
|
||||
name=NODE_NAME, location=NODE_LOCATION
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -45,5 +50,8 @@ class HttpChecker(BaseChecker):
|
|||
payload=HttpCheckerResponse(
|
||||
time=end_time - start_time,
|
||||
status_code=request.status_code
|
||||
),
|
||||
node=APINodeInfo(
|
||||
name=NODE_NAME, location=NODE_LOCATION
|
||||
)
|
||||
)
|
||||
|
|
|
@ -7,7 +7,7 @@ APP_PORT = os.environ.get("PORT", 8080)
|
|||
NODE_NAME = os.environ.get("NODE_NAME", "Default node")
|
||||
|
||||
# Node location. Will be shown in tgbot
|
||||
NODE_LOCATION = os.environ.get("NODE_LOCATION", "Undefined Location")
|
||||
NODE_LOCATION = os.environ.get("NODE_LOCATION", "🏳️🌈 Undefined, Location")
|
||||
|
||||
# Access token. Will be used for requests
|
||||
ACCESS_TOKEN = os.environ.get("ACCESS_TOKEN", "CHANGE_TOKEN_BY_ENV")
|
||||
|
|
|
@ -27,10 +27,17 @@ class HttpCheckerResponse(Payload):
|
|||
time: float
|
||||
|
||||
|
||||
@dataclass
|
||||
class APINodeInfo:
|
||||
name: str
|
||||
location: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Response:
|
||||
status: ResponseStatus
|
||||
payload: Payload
|
||||
node: APINodeInfo
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
Loading…
Reference in New Issue
Block a user