Skip to content
This repository was archived by the owner on Aug 10, 2024. It is now read-only.

Commit 1c355f8

Browse files
authored
Merge pull request #285 from frnknglrt/master
Proposed fix for #284
2 parents 5bec44b + 0603a0b commit 1c355f8

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/main/kotlin/kweb/Kweb.kt

+3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class Kweb private constructor(
112112
var plugins: List<KwebPlugin> = Collections.emptyList()
113113
var kwebConfig: KwebConfiguration = KwebDefaultConfiguration()
114114

115+
116+
115117
@Deprecated("Please use the Ktor syntax for defining page handlers instead: $buildPageReplacementCode")
116118
var buildPage: (WebBrowser.() -> Unit)? = null
117119
}
@@ -298,6 +300,7 @@ class Kweb private constructor(
298300
}
299301
} catch (e: Exception) {
300302
logger.error("Exception while receiving websocket message", e)
303+
kwebConfig.onWebsocketMessageHandlingFailure(e)
301304
}
302305
}
303306
} finally {

src/main/kotlin/kweb/config/KwebConfiguration.kt

+12
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ abstract class KwebConfiguration {
5151
logger.debug { "Configuration has been initialized successfully" }
5252
}
5353

54+
55+
/**
56+
* Override this function to handle uncaught exceptions of client callbacks.
57+
* E.g. if the browser sends a websocket message back to the kweb instance
58+
* and the message handler throws an uncaught exception, kweb will invoke
59+
* this exception handler to expose the fact that a message could not be
60+
* properly handled
61+
*/
62+
open fun onWebsocketMessageHandlingFailure(ex: Exception){
63+
64+
}
65+
5466
/**
5567
* Override the default robots.txt behavior, which is to return with a 404. Passed a Ktor [ApplicationCall]
5668
* which may be used to return whatever you wish.

src/main/kotlin/kweb/html/events/events.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ data class MouseEvent(
4444
val altKey: Boolean,
4545
val button: Int,
4646
val buttons: Int,
47-
val clientX: Int,
48-
val clientY: Int,
47+
val clientX: Float,
48+
val clientY: Float,
4949
val ctrlKey: Boolean,
5050
val metaKey: Boolean,
5151
val movementX: Int? = null,
@@ -54,8 +54,8 @@ data class MouseEvent(
5454
val screenX: Int,
5555
val screenY: Int,
5656
val shiftKey: Boolean,
57-
val x: Int = clientX,
58-
val y: Int = clientY,
57+
val x: Float = clientX,
58+
val y: Float = clientY,
5959
/** @see kweb.Element.on **/
6060
val retrieved: JsonElement = JsonNull
6161
)

src/main/resources/kweb/kweb_bootstrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function debugErr(debugToken, err, errMsg) {
8888
const message = {id: kwebClientId, error: err};
8989
sendMessage(JSON.stringify(message));
9090
} else {
91-
throw err;
91+
console.error(errMsg)
9292
}
9393
}
9494

0 commit comments

Comments
 (0)