From 86ec7f4de8d0dec41c4b062269429941f279c3b0 Mon Sep 17 00:00:00 2001 From: Hubert Van De Walle Date: Sat, 25 Apr 2020 22:46:43 +0200 Subject: [PATCH] Handle errors while querying notes --- api/src/extensions/KtormExtensions.kt | 11 ++++++----- frontend/pages/notes.vue | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/api/src/extensions/KtormExtensions.kt b/api/src/extensions/KtormExtensions.kt index 2b691e0..2d3c642 100644 --- a/api/src/extensions/KtormExtensions.kt +++ b/api/src/extensions/KtormExtensions.kt @@ -6,14 +6,15 @@ import java.sql.PreparedStatement import java.sql.ResultSet import java.sql.Types import java.util.* +import java.util.UUID as JavaUUID -class UuidBinarySqlType : SqlType(Types.BINARY, typeName = "uuidBinary") { - override fun doGetResult(rs: ResultSet, index: Int): UUID? { +class UuidBinarySqlType : SqlType(Types.BINARY, typeName = "uuidBinary") { + override fun doGetResult(rs: ResultSet, index: Int): JavaUUID? { val value = rs.getBytes(index) ?: return null - return ByteBuffer.wrap(value).let { b -> UUID(b.long, b.long) } + return ByteBuffer.wrap(value).let { b -> JavaUUID(b.long, b.long) } } - override fun doSetParameter(ps: PreparedStatement, index: Int, parameter: UUID) { + override fun doSetParameter(ps: PreparedStatement, index: Int, parameter: JavaUUID) { val bytes = ByteBuffer.allocate(16) .putLong(parameter.mostSignificantBits) .putLong(parameter.leastSignificantBits) @@ -22,6 +23,6 @@ class UuidBinarySqlType : SqlType(Types.BINARY, typeName = "uuid } } -fun BaseTable.uuidBinary(name: String): BaseTable.ColumnRegistration { +fun BaseTable.uuidBinary(name: String): BaseTable.ColumnRegistration { return registerColumn(name, UuidBinarySqlType()) } diff --git a/frontend/pages/notes.vue b/frontend/pages/notes.vue index 3fcf479..21384ff 100644 --- a/frontend/pages/notes.vue +++ b/frontend/pages/notes.vue @@ -74,14 +74,22 @@ export default { }, methods: { async loadNotes() { - await this.$axios.get('/notes').then((e) => { - this.notes = e.data - this.loading = false - }) + await this.$axios + .get('/notes') + .then((e) => { + this.notes = e.data + this.loading = false + }) + .catch((_) => {}) }, editItem(item) {}, async deleteItem(item) { - await this.$axios.delete(`/notes/${item.uuid}`).then(this.loadNotes) + try { + await this.$axios.delete(`/notes/${item.uuid}`) + } catch (_) { + } finally { + await this.loadNotes() + } }, format, },