Skip to content

Commit

Permalink
chore: kotlin error handling cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasonvdb committed Sep 23, 2024
1 parent 98e7381 commit 5b9154a
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions lib/android/src/main/java/com/reactnativeldk/LdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -798,35 +798,17 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
return promise.resolve((res as Result_ChannelIdAPIErrorZ_OK).res._a.hexEncodedString())
}

if ((res as Result_ChannelIdAPIErrorZ.Result_ChannelIdAPIErrorZ_Err).err is APIError.APIMisuseError) {
return handleReject(promise, LdkErrors.start_create_channel_fail, Error((res.err as APIError.APIMisuseError).err))
val failure = when(val error = (res as? Result_ChannelIdAPIErrorZ.Result_ChannelIdAPIErrorZ_Err)?.err) {
is APIError.APIMisuseError -> Error(error.err)
is APIError.ChannelUnavailable -> Error(error.err)
is APIError.FeeRateTooHigh -> Error(error.err)
is APIError.InvalidRoute -> Error(error.err)
is APIError.IncompatibleShutdownScript -> Error("IncompatibleShutdownScript")
is APIError.MonitorUpdateInProgress -> Error("MonitorUpdateInProgress")
else -> null
}

if (res.err is APIError.ChannelUnavailable) {
return handleReject(promise, LdkErrors.start_create_channel_fail, Error((res.err as APIError.ChannelUnavailable).err))
}

if (res.err is APIError.FeeRateTooHigh) {
return handleReject(promise, LdkErrors.start_create_channel_fail, Error((res.err as APIError.FeeRateTooHigh).err))
}

if (res.err is APIError.InvalidRoute) {
return handleReject(promise, LdkErrors.start_create_channel_fail, Error((res.err as APIError.InvalidRoute).err))
}

if (res.err is APIError.IncompatibleShutdownScript) {
return handleReject(promise, LdkErrors.start_create_channel_fail, Error("IncompatibleShutdownScript"))
}

if (res.err is APIError.MonitorUpdateInProgress) {
return handleReject(promise, LdkErrors.start_create_channel_fail, Error("MonitorUpdateInProgress"))
}

if (res.err is APIError.ChannelUnavailable) {
return handleReject(promise, LdkErrors.start_create_channel_fail, Error((res.err as APIError.ChannelUnavailable).err))
}

return handleReject(promise, LdkErrors.start_create_channel_fail)
return handleReject(promise, LdkErrors.start_create_channel_fail, failure)
}

@ReactMethod
Expand Down

0 comments on commit 5b9154a

Please sign in to comment.