Better error types

This commit is contained in:
Fernando Falci 2021-06-08 21:04:47 +02:00
parent 8767e9b786
commit 4e9be1e418
No known key found for this signature in database
GPG key ID: AB787B833D90361D
2 changed files with 8 additions and 6 deletions

View file

@ -2212,15 +2212,16 @@ class RPC extends RPCBase {
const ns = await this.chain.db.getNameState(nameHash);
if (!ns || !ns.owner)
throw new RPCError(errs.TYPE_ERROR, 'Cannot find the name owner.');
throw new RPCError(errs.MISC_ERROR, 'Cannot find the name owner.');
const coin = await this.chain.getCoin(ns.owner.hash, ns.owner.index);
if (!coin)
if (!coin) {
throw new RPCError(
errs.INVALID_ADDRESS_OR_KEY,
errs.DATABASE_ERROR,
'Cannot find the owner\'s address.'
);
}
const address = coin.address.toString(this.network);
return this.verifyMessage([address, sig, str], help);

View file

@ -1606,15 +1606,16 @@ class RPC extends RPCBase {
const ns = await wallet.getNameStateByName(name);
if (!ns || !ns.owner)
throw new RPCError(errs.TYPE_ERROR, 'Cannot find the name owner.');
throw new RPCError(errs.MISC_ERROR, 'Cannot find the name owner.');
const coin = await wallet.getCoin(ns.owner.hash, ns.owner.index);
if (!coin)
if (!coin) {
throw new RPCError(
errs.INVALID_ADDRESS_OR_KEY,
errs.DATABASE_ERROR,
'Cannot find the owner\'s address.'
);
}
const address = coin.address.toString(this.network);
return this.signMessage([address, str], help);