stacker.news/wallets/errors.js

96 lines
2.6 KiB
JavaScript
Raw Normal View History

2024-10-23 17:42:34 +00:00
export class InvoiceCanceledError extends Error {
constructor (invoice, actionError) {
super(actionError ?? `invoice canceled: ${invoice.hash}`)
2024-10-23 17:42:34 +00:00
this.name = 'InvoiceCanceledError'
this.invoice = invoice
2024-10-23 17:42:34 +00:00
this.actionError = actionError
}
}
export class InvoiceExpiredError extends Error {
constructor (invoice) {
super(`invoice expired: ${invoice.hash}`)
2024-10-23 17:42:34 +00:00
this.name = 'InvoiceExpiredError'
this.invoice = invoice
2024-10-23 17:42:34 +00:00
}
}
2024-11-25 00:53:57 +00:00
export class WalletError extends Error {}
export class WalletPaymentError extends WalletError {}
export class WalletConfigurationError extends WalletError {}
export class WalletNotEnabledError extends WalletConfigurationError {
2024-11-25 00:53:57 +00:00
constructor (name) {
super(`wallet is not enabled: ${name}`)
this.name = 'WalletNotEnabledError'
this.wallet = name
this.reason = 'wallet is not enabled'
2024-11-25 00:53:57 +00:00
}
}
export class WalletSendNotConfiguredError extends WalletConfigurationError {
constructor (name) {
super(`wallet send is not configured: ${name}`)
this.name = 'WalletSendNotConfiguredError'
this.wallet = name
this.reason = 'wallet send is not configured'
}
}
export class WalletSenderError extends WalletPaymentError {
2024-11-26 02:29:28 +00:00
constructor (name, invoice, message) {
super(`${name} failed to pay invoice ${invoice.hash}: ${message}`)
this.name = 'WalletSenderError'
this.wallet = name
2024-11-26 02:29:28 +00:00
this.invoice = invoice
this.reason = message
2024-11-25 00:53:57 +00:00
}
}
export class WalletReceiverError extends WalletPaymentError {
constructor (invoice) {
super(`payment forwarding failed for invoice ${invoice.hash}`)
this.name = 'WalletReceiverError'
this.invoice = invoice
}
}
export class WalletsNotAvailableError extends WalletConfigurationError {
constructor () {
super('no wallet available')
this.name = 'WalletsNotAvailableError'
2024-11-25 00:53:57 +00:00
}
}
export class WalletAggregateError extends WalletError {
constructor (errors, invoice) {
super('WalletAggregateError')
this.name = 'WalletAggregateError'
2024-11-28 00:35:44 +00:00
this.errors = errors.reduce((acc, e) => {
if (Array.isArray(e?.errors)) {
acc.push(...e.errors)
} else {
acc.push(e)
}
return acc
}, [])
this.invoice = invoice
2024-11-25 00:53:57 +00:00
}
}
export class WalletPaymentAggregateError extends WalletPaymentError {
constructor (errors, invoice) {
super('WalletPaymentAggregateError')
this.name = 'WalletPaymentAggregateError'
2024-11-28 00:35:44 +00:00
this.errors = errors.reduce((acc, e) => {
if (Array.isArray(e?.errors)) {
acc.push(...e.errors)
} else {
acc.push(e)
}
return acc
}, []).filter(e => e instanceof WalletPaymentError)
this.invoice = invoice
}
}