Skip to content

Commit 5eafcf8

Browse files
committed
add exception converts
1 parent 1937fc2 commit 5eafcf8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/jvmMain/kotlin/spp/protocol/marshall/ServiceExceptionConverter.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
package spp.protocol.marshall
1919

2020
import io.vertx.serviceproxy.ServiceException
21+
import spp.protocol.platform.auth.RolePermission
22+
import spp.protocol.service.error.InstrumentAccessDenied
2123
import spp.protocol.service.error.LiveInstrumentException
24+
import spp.protocol.service.error.PermissionAccessDenied
2225

2326
object ServiceExceptionConverter {
2427

25-
fun fromEventBusException(exception: String): ServiceException {
28+
fun fromEventBusException(exception: String, toEventBusException: Boolean = false): ServiceException {
2629
return if (exception.startsWith("EventBusException")) {
2730
var exceptionType = exception.substringAfter("EventBusException:")
2831
exceptionType = exceptionType.substringBefore("[")
@@ -33,6 +36,16 @@ object ServiceExceptionConverter {
3336
LiveInstrumentException(
3437
LiveInstrumentException.ErrorType.valueOf(exceptionParams),
3538
exceptionMessage
39+
).let { if (toEventBusException) it.toEventBusException() else it }
40+
} else if (InstrumentAccessDenied::class.java.simpleName == exceptionType) {
41+
InstrumentAccessDenied(
42+
exceptionParams,
43+
exceptionMessage
44+
).let { if (toEventBusException) it.toEventBusException() else it }
45+
} else if (PermissionAccessDenied::class.java.simpleName == exceptionType) {
46+
PermissionAccessDenied(
47+
RolePermission.valueOf(exceptionParams),
48+
exceptionMessage
3649
).toEventBusException()
3750
} else {
3851
throw UnsupportedOperationException(exceptionType)

0 commit comments

Comments
 (0)