Chore/unhashed description expressive error (#894)
* dont assume field * expressive error for desciprion_hash and unhashed_description in format that isnt hex
This commit is contained in:
parent
7bba742faf
commit
790f0efda7
|
@ -1,7 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
from binascii import unhexlify
|
import binascii
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from typing import Dict, List, Optional, Tuple, Union
|
from typing import Dict, List, Optional, Tuple, Union
|
||||||
|
@ -152,11 +152,23 @@ class CreateInvoiceData(BaseModel):
|
||||||
|
|
||||||
async def api_payments_create_invoice(data: CreateInvoiceData, wallet: Wallet):
|
async def api_payments_create_invoice(data: CreateInvoiceData, wallet: Wallet):
|
||||||
if data.description_hash:
|
if data.description_hash:
|
||||||
description_hash = unhexlify(data.description_hash)
|
try:
|
||||||
|
description_hash = binascii.unhexlify(data.description_hash)
|
||||||
|
except binascii.Error:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail="'description_hash' must be a valid hex string",
|
||||||
|
)
|
||||||
unhashed_description = b""
|
unhashed_description = b""
|
||||||
memo = ""
|
memo = ""
|
||||||
elif data.unhashed_description:
|
elif data.unhashed_description:
|
||||||
unhashed_description = unhexlify(data.unhashed_description)
|
try:
|
||||||
|
unhashed_description = binascii.unhexlify(data.unhashed_description)
|
||||||
|
except binascii.Error:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail="'unhashed_description' must be a valid hex string",
|
||||||
|
)
|
||||||
description_hash = b""
|
description_hash = b""
|
||||||
memo = ""
|
memo = ""
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user