adds better logging mechanisms to control internal vs external errors
This commit is contained in:
parent
f4d5c6e62f
commit
4a552fb201
2 changed files with 20 additions and 21 deletions
|
@ -99,6 +99,7 @@ async def process_json(app, body: dict) -> dict:
|
||||||
@atomic
|
@atomic
|
||||||
async def api_endpoint(request: web.Request):
|
async def api_endpoint(request: web.Request):
|
||||||
try:
|
try:
|
||||||
|
web.access_logger.info(f'Forwarded headers: {request.forwarded}')
|
||||||
body = await request.json()
|
body = await request.json()
|
||||||
if type(body) is list or type(body) is dict:
|
if type(body) is list or type(body) is dict:
|
||||||
if type(body) is list:
|
if type(body) is list:
|
||||||
|
@ -109,8 +110,6 @@ async def api_endpoint(request: web.Request):
|
||||||
else:
|
else:
|
||||||
return web.json_response(await process_json(request.app, body))
|
return web.json_response(await process_json(request.app, body))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f'Exception raised by request from {request.remote}: {e}')
|
|
||||||
logger.debug(f'Request headers: {request.headers}')
|
|
||||||
return make_error('INVALID_REQUEST', e)
|
return make_error('INVALID_REQUEST', e)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import hashlib
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
import ecdsa
|
import ecdsa
|
||||||
|
from aiohttp import ClientConnectorError
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives.serialization import load_der_public_key
|
from cryptography.hazmat.primitives.serialization import load_der_public_key
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
|
@ -20,7 +21,7 @@ ID_LIST = {'claim_id', 'parent_id', 'comment_id', 'channel_id'}
|
||||||
|
|
||||||
ERRORS = {
|
ERRORS = {
|
||||||
'INVALID_PARAMS': {'code': -32602, 'message': 'Invalid Method Parameter(s).'},
|
'INVALID_PARAMS': {'code': -32602, 'message': 'Invalid Method Parameter(s).'},
|
||||||
'INTERNAL': {'code': -32603, 'message': 'Internal Server Error.'},
|
'INTERNAL': {'code': -32603, 'message': 'Internal Server Error. Please notify a LBRY Administrator.'},
|
||||||
'METHOD_NOT_FOUND': {'code': -32601, 'message': 'The method does not exist / is not available.'},
|
'METHOD_NOT_FOUND': {'code': -32601, 'message': 'The method does not exist / is not available.'},
|
||||||
'INVALID_REQUEST': {'code': -32600, 'message': 'The JSON sent is not a valid Request object.'},
|
'INVALID_REQUEST': {'code': -32600, 'message': 'The JSON sent is not a valid Request object.'},
|
||||||
'PARSE_ERROR': {
|
'PARSE_ERROR': {
|
||||||
|
@ -42,22 +43,21 @@ def make_error(error, exc=None) -> dict:
|
||||||
|
|
||||||
async def resolve_channel_claim(app, channel_id, channel_name):
|
async def resolve_channel_claim(app, channel_id, channel_name):
|
||||||
lbry_url = f'lbry://{channel_name}#{channel_id}'
|
lbry_url = f'lbry://{channel_name}#{channel_id}'
|
||||||
resolve_body = {
|
resolve_body = {'method': 'resolve', 'params': {'urls': [lbry_url]}}
|
||||||
'method': 'resolve',
|
try:
|
||||||
'params': {
|
async with aiohttp.request('POST', app['config']['LBRYNET'], json=resolve_body) as req:
|
||||||
'urls': [lbry_url, ]
|
try:
|
||||||
}
|
resp = await req.json()
|
||||||
}
|
except JSONDecodeError as jde:
|
||||||
async with aiohttp.request('POST', app['config']['LBRYNET'], json=resolve_body) as req:
|
logger.exception(jde.msg)
|
||||||
try:
|
raise Exception('JSON Decode Error in Claim Resolution')
|
||||||
resp = await req.json()
|
finally:
|
||||||
except JSONDecodeError as jde:
|
if 'result' in resp:
|
||||||
logger.exception(jde.msg)
|
return resp['result'].get(lbry_url)
|
||||||
raise Exception('JSON Decode Error in Claim Resolution')
|
raise ValueError('claim resolution yields error', {'error': resp['error']})
|
||||||
finally:
|
except (ConnectionRefusedError, ClientConnectorError):
|
||||||
if 'result' in resp:
|
logger.critical("Connection to the LBRYnet daemon failed, make sure it's running.")
|
||||||
return resp['result'].get(lbry_url)
|
raise Exception("Server cannot verify delete signature")
|
||||||
raise ValueError('claim resolution yields error', {'error': resp['error']})
|
|
||||||
|
|
||||||
|
|
||||||
def get_encoded_signature(signature):
|
def get_encoded_signature(signature):
|
||||||
|
@ -83,8 +83,8 @@ def is_signature_valid(encoded_signature, signature_digest, public_key_bytes):
|
||||||
public_key = load_der_public_key(public_key_bytes, default_backend())
|
public_key = load_der_public_key(public_key_bytes, default_backend())
|
||||||
public_key.verify(encoded_signature, signature_digest, ec.ECDSA(Prehashed(hashes.SHA256())))
|
public_key.verify(encoded_signature, signature_digest, ec.ECDSA(Prehashed(hashes.SHA256())))
|
||||||
return True
|
return True
|
||||||
except (ValueError, InvalidSignature) as err:
|
except (ValueError, InvalidSignature):
|
||||||
logger.debug('Signature Valiadation Failed: %s', err)
|
logger.exception('Signature validation failed')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue