Skip to content

Commit 5b9154a

Browse files
committed
chore: kotlin error handling cleanup
1 parent 98e7381 commit 5b9154a

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

lib/android/src/main/java/com/reactnativeldk/LdkModule.kt

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -798,35 +798,17 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
798798
return promise.resolve((res as Result_ChannelIdAPIErrorZ_OK).res._a.hexEncodedString())
799799
}
800800

801-
if ((res as Result_ChannelIdAPIErrorZ.Result_ChannelIdAPIErrorZ_Err).err is APIError.APIMisuseError) {
802-
return handleReject(promise, LdkErrors.start_create_channel_fail, Error((res.err as APIError.APIMisuseError).err))
801+
val failure = when(val error = (res as? Result_ChannelIdAPIErrorZ.Result_ChannelIdAPIErrorZ_Err)?.err) {
802+
is APIError.APIMisuseError -> Error(error.err)
803+
is APIError.ChannelUnavailable -> Error(error.err)
804+
is APIError.FeeRateTooHigh -> Error(error.err)
805+
is APIError.InvalidRoute -> Error(error.err)
806+
is APIError.IncompatibleShutdownScript -> Error("IncompatibleShutdownScript")
807+
is APIError.MonitorUpdateInProgress -> Error("MonitorUpdateInProgress")
808+
else -> null
803809
}
804810

805-
if (res.err is APIError.ChannelUnavailable) {
806-
return handleReject(promise, LdkErrors.start_create_channel_fail, Error((res.err as APIError.ChannelUnavailable).err))
807-
}
808-
809-
if (res.err is APIError.FeeRateTooHigh) {
810-
return handleReject(promise, LdkErrors.start_create_channel_fail, Error((res.err as APIError.FeeRateTooHigh).err))
811-
}
812-
813-
if (res.err is APIError.InvalidRoute) {
814-
return handleReject(promise, LdkErrors.start_create_channel_fail, Error((res.err as APIError.InvalidRoute).err))
815-
}
816-
817-
if (res.err is APIError.IncompatibleShutdownScript) {
818-
return handleReject(promise, LdkErrors.start_create_channel_fail, Error("IncompatibleShutdownScript"))
819-
}
820-
821-
if (res.err is APIError.MonitorUpdateInProgress) {
822-
return handleReject(promise, LdkErrors.start_create_channel_fail, Error("MonitorUpdateInProgress"))
823-
}
824-
825-
if (res.err is APIError.ChannelUnavailable) {
826-
return handleReject(promise, LdkErrors.start_create_channel_fail, Error((res.err as APIError.ChannelUnavailable).err))
827-
}
828-
829-
return handleReject(promise, LdkErrors.start_create_channel_fail)
811+
return handleReject(promise, LdkErrors.start_create_channel_fail, failure)
830812
}
831813

832814
@ReactMethod

0 commit comments

Comments
 (0)