From 5763aa3b0004b678d7791b32e1a92b6facb9b17e Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 1 Nov 2019 17:44:31 +0100 Subject: Better exception handling in server-side interfaces. --- .../pl/treksoft/kvision/remote/KVServiceManager.kt | 40 +++++++++++++--------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'kvision-modules/kvision-server-jooby') diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index bb682351..d81dc7a7 100644 --- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -106,8 +106,9 @@ actual open class KVServiceManager actual constructor(val serviceClass: ) ) } catch (e: Exception) { - LOG.error(e.message, e) - res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error")) + if (!(e is ServiceException)) LOG.error(e.message, e) + res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error", + exceptionType = e.javaClass.canonicalName)) } } }.invoke(this) @@ -145,8 +146,9 @@ actual open class KVServiceManager actual constructor(val serviceClass: ) ) } catch (e: Exception) { - LOG.error(e.message, e) - res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error")) + if (!(e is ServiceException)) LOG.error(e.message, e) + res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error", + exceptionType = e.javaClass.canonicalName)) } } } else { @@ -188,8 +190,9 @@ actual open class KVServiceManager actual constructor(val serviceClass: ) ) } catch (e: Exception) { - LOG.error(e.message, e) - res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error")) + if (!(e is ServiceException)) LOG.error(e.message, e) + res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error", + exceptionType = e.javaClass.canonicalName)) } } } else { @@ -233,8 +236,9 @@ actual open class KVServiceManager actual constructor(val serviceClass: ) ) } catch (e: Exception) { - LOG.error(e.message, e) - res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error")) + if (!(e is ServiceException)) LOG.error(e.message, e) + res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error", + exceptionType = e.javaClass.canonicalName)) } } } else { @@ -279,8 +283,9 @@ actual open class KVServiceManager actual constructor(val serviceClass: ) ) } catch (e: Exception) { - LOG.error(e.message, e) - res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error")) + if (!(e is ServiceException)) LOG.error(e.message, e) + res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error", + exceptionType = e.javaClass.canonicalName)) } } } else { @@ -327,8 +332,9 @@ actual open class KVServiceManager actual constructor(val serviceClass: ) ) } catch (e: Exception) { - LOG.error(e.message, e) - res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error")) + if (!(e is ServiceException)) LOG.error(e.message, e) + res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error", + exceptionType = e.javaClass.canonicalName)) } } } else { @@ -440,8 +446,9 @@ actual open class KVServiceManager actual constructor(val serviceClass: ) ) } catch (e: Exception) { - LOG.error(e.message, e) - res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error")) + if (!(e is ServiceException)) LOG.error(e.message, e) + res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error", + exceptionType = e.javaClass.canonicalName)) } } } else { @@ -482,8 +489,9 @@ actual open class KVServiceManager actual constructor(val serviceClass: ) ) } catch (e: Exception) { - LOG.error(e.message, e) - res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error")) + if (!(e is ServiceException)) LOG.error(e.message, e) + res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = e.message ?: "Error", + exceptionType = e.javaClass.canonicalName)) } } } else { -- cgit