Better error message on invalid payment req
This commit is contained in:
@@ -22,6 +22,9 @@ pub enum Error {
|
||||
#[error("NyxdError - {0}")]
|
||||
NyxdError(#[from] nym_validator_client::nyxd::error::NyxdError),
|
||||
|
||||
#[error("Invalid payment requested")]
|
||||
InvalidPaymentRequest,
|
||||
|
||||
#[error("Bad deposit address")]
|
||||
BadAddress,
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ pub async fn claim_payment(
|
||||
.storage
|
||||
.manager
|
||||
.get_payment(&claim_payment_request_body.serial_number)
|
||||
.await?;
|
||||
.await?
|
||||
.ok_or(Error::InvalidPaymentRequest)?;
|
||||
|
||||
let recipient = AccountId::from_str(&claim_payment_request_body.deposit_address)
|
||||
.map_err(|_| Error::BadAddress)?;
|
||||
|
||||
@@ -25,7 +25,7 @@ pub struct State {
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub(crate) async fn new(storage: Storage, client: Client, config: Config) -> Self {
|
||||
pub(crate) fn new(storage: Storage, client: Client, config: Config) -> Self {
|
||||
State {
|
||||
storage,
|
||||
client,
|
||||
|
||||
@@ -10,7 +10,10 @@ pub(crate) struct StorageManager {
|
||||
|
||||
// all SQL goes here
|
||||
impl StorageManager {
|
||||
pub(crate) async fn get_payment(&self, serial_number: &str) -> Result<Payment, sqlx::Error> {
|
||||
pub(crate) async fn get_payment(
|
||||
&self,
|
||||
serial_number: &str,
|
||||
) -> Result<Option<Payment>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Payment,
|
||||
r#"
|
||||
@@ -20,7 +23,7 @@ impl StorageManager {
|
||||
"#,
|
||||
serial_number
|
||||
)
|
||||
.fetch_one(&self.connection_pool)
|
||||
.fetch_optional(&self.connection_pool)
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user