Skip to content

Commit

Permalink
fix: 400 error for tx submit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewWestberg committed Nov 22, 2024
1 parent 30bf2ba commit a18eddf
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,17 @@ fun Routing.createCardanoRoutes() {
try {
val request = receive<SubmitTransactionRequest>()
val response = cardanoRepository.submitTransaction(request.cborHex.hexToByteArray().toByteString())
songRepository.updateSongMintingStatus(request.songId, MintingStatus.MintingPaymentSubmitted)
respond(HttpStatusCode.Accepted, SubmitTransactionResponse(response.txId, response.result))
if (!response.txId.isNullOrBlank()) {
songRepository.updateSongMintingStatus(request.songId, MintingStatus.MintingPaymentSubmitted)
respond(HttpStatusCode.Accepted, SubmitTransactionResponse(response.txId, response.result))
} else {
songRepository.updateSongMintingStatus(
request.songId,
MintingStatus.MintingPaymentException,
"error submitting minting payment: ${response.result}"
)
respond(HttpStatusCode.BadRequest, SubmitTransactionResponse(response.txId, response.result))
}
} catch (e: Exception) {
log.error("Failed to submit transaction: ${e.message}")
throw e
Expand Down Expand Up @@ -180,7 +189,11 @@ fun Routing.createCardanoRoutes() {
try {
val request = receive<SubmitTxRequest>()
val response = cardanoRepository.submitTransaction(request.cborHex.hexToByteArray().toByteString())
respond(HttpStatusCode.Accepted, SubmitTransactionResponse(response.txId, response.result))
if (!response.txId.isNullOrBlank()) {
respond(HttpStatusCode.Accepted, SubmitTransactionResponse(response.txId, response.result))
} else {
respond(HttpStatusCode.BadRequest, SubmitTransactionResponse(response.txId, response.result))
}
} catch (e: Exception) {
log.error { "Failed to submit transaction: ${e.message}" }
throw e
Expand Down

0 comments on commit a18eddf

Please sign in to comment.