fix: 🐛 Better response error handling
parent
e8c91e260c
commit
e12c28cb8e
29
main.js
29
main.js
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue