diff --git a/src/main/kotlin/kweb/Kweb.kt b/src/main/kotlin/kweb/Kweb.kt index f2e4533ae6..bc6584d167 100755 --- a/src/main/kotlin/kweb/Kweb.kt +++ b/src/main/kotlin/kweb/Kweb.kt @@ -112,6 +112,8 @@ class Kweb private constructor( var plugins: List = Collections.emptyList() var kwebConfig: KwebConfiguration = KwebDefaultConfiguration() + + @Deprecated("Please use the Ktor syntax for defining page handlers instead: $buildPageReplacementCode") var buildPage: (WebBrowser.() -> Unit)? = null } @@ -298,6 +300,7 @@ class Kweb private constructor( } } catch (e: Exception) { logger.error("Exception while receiving websocket message", e) + kwebConfig.onWebsocketMessageHandlingFailure(e) } } } finally { diff --git a/src/main/kotlin/kweb/config/KwebConfiguration.kt b/src/main/kotlin/kweb/config/KwebConfiguration.kt index a162559599..e3c15f2d65 100644 --- a/src/main/kotlin/kweb/config/KwebConfiguration.kt +++ b/src/main/kotlin/kweb/config/KwebConfiguration.kt @@ -51,6 +51,18 @@ abstract class KwebConfiguration { logger.debug { "Configuration has been initialized successfully" } } + + /** + * Override this function to handle uncaught exceptions of client callbacks. + * E.g. if the browser sends a websocket message back to the kweb instance + * and the message handler throws an uncaught exception, kweb will invoke + * this exception handler to expose the fact that a message could not be + * properly handled + */ + open fun onWebsocketMessageHandlingFailure(ex: Exception){ + + } + /** * Override the default robots.txt behavior, which is to return with a 404. Passed a Ktor [ApplicationCall] * which may be used to return whatever you wish. diff --git a/src/main/kotlin/kweb/html/events/events.kt b/src/main/kotlin/kweb/html/events/events.kt index 5e5f194874..4cd387edaa 100644 --- a/src/main/kotlin/kweb/html/events/events.kt +++ b/src/main/kotlin/kweb/html/events/events.kt @@ -44,8 +44,8 @@ data class MouseEvent( val altKey: Boolean, val button: Int, val buttons: Int, - val clientX: Int, - val clientY: Int, + val clientX: Float, + val clientY: Float, val ctrlKey: Boolean, val metaKey: Boolean, val movementX: Int? = null, @@ -54,8 +54,8 @@ data class MouseEvent( val screenX: Int, val screenY: Int, val shiftKey: Boolean, - val x: Int = clientX, - val y: Int = clientY, + val x: Float = clientX, + val y: Float = clientY, /** @see kweb.Element.on **/ val retrieved: JsonElement = JsonNull ) diff --git a/src/main/resources/kweb/kweb_bootstrap.js b/src/main/resources/kweb/kweb_bootstrap.js index 7cf6b31a31..22ca58ceb5 100644 --- a/src/main/resources/kweb/kweb_bootstrap.js +++ b/src/main/resources/kweb/kweb_bootstrap.js @@ -88,7 +88,7 @@ function debugErr(debugToken, err, errMsg) { const message = {id: kwebClientId, error: err}; sendMessage(JSON.stringify(message)); } else { - throw err; + console.error(errMsg) } }