fix: 🐛 Better response error handling

main
Keith Irwin 2024-04-20 19:05:48 -06:00
parent e8c91e260c
commit e12c28cb8e
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
2 changed files with 18 additions and 13 deletions

29
main.js
View File

@ -5,7 +5,7 @@ module.exports = class Wallet {
address; viewKey; restoreHeight;
constructor (settings) {
// Open wallet
try {
this.rpc('open_wallet', {
@ -26,22 +26,27 @@ module.exports = class Wallet {
viewKey: settings.viewKey,
password: settings.password
})
console.log(`Created wallet "${this.wallet}".`)
console.log(`Created wallet "${settings.wallet}".`)
} catch (createErr) {
console.error(`Failed to open wallet "${this.wallet}": ${openErr}`)
console.error(`Failed to create wallet "${this.wallet}": ${createErr}`)
console.error(`Failed to open wallet "${settings.wallet}": ${openErr}`)
console.error(`Failed to create wallet "${settings.wallet}": ${createErr}`)
}
}
}
async rpc (method, params) {
return await axios.post(this.url, {
jsonrpc: '2.0',
id: '0',
method: method,
params: params,
})
}
async rpc(method, params) {
let res; try {
res = await axios.post(`${settings.url}/json_rpc`, {
jsonrpc: '2.0',
id: '0',
method: method,
params: params,
})
if (res.status!==200) throw res.data
} catch (err) {
console.error(err)
}
}
}

View File

@ -1,7 +1,7 @@
{
"name": "monero-wallet-rpc-js",
"type": "commonjs",
"version": "1.1.7",
"version": "1.1.8",
"description": "Javascript wrapper for monero-wallet-rpc calls",
"main": "main.js",
"scripts": {