fix: return "message" instead of "error" so it is handled better at the client.

This commit is contained in:
fiatjaf 2020-11-10 22:59:50 -03:00
parent eaec3480e6
commit d4e30356c7
3 changed files with 15 additions and 7 deletions

View File

@ -565,7 +565,12 @@ new Vue({
})
.catch(err => {
dismissAuthMsg()
LNbits.utils.notifyApiError(err)
this.$q.notify({
message: `Authentication failed. ${this.parse.lnurlauth.domain} says:`,
caption: err.response.data.message,
type: 'warning',
timeout: 5000
})
})
},
deleteWallet: function (walletId, user) {

View File

@ -300,7 +300,7 @@ async def api_lnurlscan(code: str):
try:
url = lnurl.Lnurl(code)
except ValueError:
return jsonify({"error": "invalid lnurl"}), HTTPStatus.BAD_REQUEST
return jsonify({"message": "invalid lnurl"}), HTTPStatus.BAD_REQUEST
domain = urlparse(url.url).netloc
@ -315,19 +315,22 @@ async def api_lnurlscan(code: str):
async with httpx.AsyncClient() as client:
r = await client.get(url.url, timeout=40)
if r.is_error:
return jsonify({"domain": domain, "error": "failed to get parameters"}), HTTPStatus.SERVICE_UNAVAILABLE
return (
jsonify({"domain": domain, "message": "failed to get parameters"}),
HTTPStatus.SERVICE_UNAVAILABLE,
)
try:
jdata = json.loads(r.text)
data: lnurl.LnurlResponseModel = lnurl.LnurlResponse.from_dict(jdata)
except (json.decoder.JSONDecodeError, lnurl.exceptions.LnurlResponseException):
return (
jsonify({"domain": domain, "error": f"got invalid response '{r.text[:200]}'"}),
jsonify({"domain": domain, "message": f"got invalid response '{r.text[:200]}'"}),
HTTPStatus.SERVICE_UNAVAILABLE,
)
if type(data) is lnurl.LnurlChannelResponse:
return jsonify({"domain": domain, "kind": "channel", "error": "unsupported"}), HTTPStatus.BAD_REQUEST
return jsonify({"domain": domain, "kind": "channel", "message": "unsupported"}), HTTPStatus.BAD_REQUEST
params.update(**data.dict())
@ -368,4 +371,4 @@ async def api_perform_lnurlauth():
await perform_lnurlauth(g.data["callback"])
return "", HTTPStatus.OK
except Exception as exc:
return jsonify({"error": str(exc)}), HTTPStatus.SERVICE_UNAVAILABLE
return jsonify({"message": str(exc)}), HTTPStatus.SERVICE_UNAVAILABLE

View File

@ -69,7 +69,7 @@ async def api_usermanager_users_delete(user_id):
async def api_usermanager_activate_extension():
user = get_user(g.data["userid"])
if not user:
return jsonify({"error": "no such user"}), HTTPStatus.NO_CONTENT
return jsonify({"message": "no such user"}), HTTPStatus.NOT_FOUND
update_user_extension(user_id=g.data["userid"], extension=g.data["extension"], active=g.data["active"])
return jsonify({"extension": "updated"}), HTTPStatus.CREATED