♿ Error handing
This commit is contained in:
		@@ -1,8 +1,6 @@
 | 
			
		||||
package dev.solsynth.snConnect.commands
 | 
			
		||||
 | 
			
		||||
import dev.solsynth.snConnect.services.SnOrderService
 | 
			
		||||
import dev.solsynth.snConnect.services.SnService
 | 
			
		||||
import dev.solsynth.snConnect.services.SnTransactionService
 | 
			
		||||
import dev.solsynth.snConnect.services.*
 | 
			
		||||
import net.md_5.bungee.api.chat.ClickEvent
 | 
			
		||||
import net.md_5.bungee.api.chat.TextComponent
 | 
			
		||||
import net.milkbowl.vault.economy.Economy
 | 
			
		||||
@@ -40,8 +38,21 @@ class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandE
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    p0.sendMessage(ChatColor.GRAY.toString() + "Confirming order, please stand by...");
 | 
			
		||||
                    val order = orderSrv.getOrder(orderNumber);
 | 
			
		||||
                    p0.sendMessage(ChatColor.GRAY.toString() + "Confirming payment, please stand by...");
 | 
			
		||||
 | 
			
		||||
                    val order: SnOrder
 | 
			
		||||
                    try {
 | 
			
		||||
                        order = orderSrv.getOrder(orderNumber);
 | 
			
		||||
                    } catch (_: Exception) {
 | 
			
		||||
                        p0.sendMessage(ChatColor.RED.toString() + "An error occurred while pulling transaction. Make sure the order is exists then try again later.")
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if (order.status != 1L) {
 | 
			
		||||
                        p0.sendMessage(ChatColor.RED.toString() + "Order was not paid yet.");
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    val bal = order.amount.toDouble() * 100;
 | 
			
		||||
                    eco?.depositPlayer(p0.player, bal)
 | 
			
		||||
 | 
			
		||||
@@ -65,7 +76,13 @@ class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandE
 | 
			
		||||
 | 
			
		||||
                p0.sendMessage(ChatColor.GRAY.toString() + "Creating order, please stand by...");
 | 
			
		||||
 | 
			
		||||
                val order = orderSrv.createOrder("Deposit to Highland MC", amount / 100);
 | 
			
		||||
                val order: SnOrder
 | 
			
		||||
                try {
 | 
			
		||||
                    order = orderSrv.createOrder("Deposit to Highland MC", amount / 100);
 | 
			
		||||
                } catch (_: Exception) {
 | 
			
		||||
                    p0.sendMessage(ChatColor.RED.toString() + "An error occurred while creating order. Try again later.")
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                val linkComponent =
 | 
			
		||||
                    TextComponent(ChatColor.GOLD.toString() + ChatColor.UNDERLINE.toString() + ChatColor.BOLD.toString() + "click here")
 | 
			
		||||
@@ -116,14 +133,21 @@ class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandE
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                val transactionSrv = SnTransactionService(sn);
 | 
			
		||||
                val transaction = transactionSrv.makeTransaction(bal, "Withdraw from Highland MC", walletId);
 | 
			
		||||
                try {
 | 
			
		||||
                    val transactionSrv = SnTransactionService(sn);
 | 
			
		||||
                    val transaction = transactionSrv.makeTransaction(bal, "Withdraw from Highland MC", walletId);
 | 
			
		||||
                    val transactionHintComponent =
 | 
			
		||||
                        TextComponent(ChatColor.GREEN.toString() + "Done! transaction number " + ChatColor.WHITE + ChatColor.BOLD + "#${transaction.id}")
 | 
			
		||||
 | 
			
		||||
                    p0.playSound(p0.player!!, Sound.BLOCK_ANVIL_PLACE, 1.0F, 1.0F)
 | 
			
		||||
                    p0.spigot().sendMessage(transactionHintComponent)
 | 
			
		||||
                } catch (_: Exception) {
 | 
			
		||||
                    eco?.depositPlayer(p0.player, "Withdraw to Source Point Failed - Refund", amount)
 | 
			
		||||
                    p0.sendMessage(ChatColor.RED.toString() + "An error occurred while making transaction. Make sure your wallet is exists then try again later.")
 | 
			
		||||
                    return true
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                val transactionHintComponent =
 | 
			
		||||
                    TextComponent(ChatColor.GREEN.toString() + "Done! transaction number " + ChatColor.WHITE + ChatColor.BOLD + "#${transaction.id}")
 | 
			
		||||
 | 
			
		||||
                p0.playSound(p0.player!!, Sound.BLOCK_ANVIL_PLACE, 1.0F, 1.0F)
 | 
			
		||||
                p0.spigot().sendMessage(transactionHintComponent)
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            else -> {
 | 
			
		||||
 
 | 
			
		||||
@@ -59,8 +59,8 @@ class SnTransactionService(private val sn: SnService) {
 | 
			
		||||
            .build()
 | 
			
		||||
 | 
			
		||||
        sn.client.newCall(request).execute().use { response ->
 | 
			
		||||
            if (!response.isSuccessful) throw IOException("Unexpected code $response")
 | 
			
		||||
            val responseBody = response.body!!.string()
 | 
			
		||||
            if (!response.isSuccessful) throw IOException("Unexpected code $response - $responseBody")
 | 
			
		||||
            val out = json.decodeFromString<SnTransaction>(responseBody)
 | 
			
		||||
 | 
			
		||||
            return out
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user