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

Commit

Permalink
Merge pull request #285 from frnknglrt/master
Browse files Browse the repository at this point in the history
Proposed fix for #284
  • Loading branch information
sanity authored Aug 16, 2022
2 parents 5bec44b + 0603a0b commit 1c355f8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/main/kotlin/kweb/Kweb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class Kweb private constructor(
var plugins: List<KwebPlugin> = Collections.emptyList()
var kwebConfig: KwebConfiguration = KwebDefaultConfiguration()



@Deprecated("Please use the Ktor syntax for defining page handlers instead: $buildPageReplacementCode")
var buildPage: (WebBrowser.() -> Unit)? = null
}
Expand Down Expand Up @@ -298,6 +300,7 @@ class Kweb private constructor(
}
} catch (e: Exception) {
logger.error("Exception while receiving websocket message", e)
kwebConfig.onWebsocketMessageHandlingFailure(e)
}
}
} finally {
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/kweb/config/KwebConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/kweb/html/events/events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/kweb/kweb_bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 1c355f8

Please sign in to comment.