Skip to content

Commit 789de16

Browse files
committed
detectErrorType
1 parent 53654d5 commit 789de16

2 files changed

Lines changed: 28 additions & 23 deletions

File tree

android/src/main/java/com/margelo/nitro/rive/HybridRiveView.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.rive.RiveReactNativeView
1010
import com.rive.ViewConfiguration
1111
import app.rive.runtime.kotlin.core.Fit as RiveFit
1212
import app.rive.runtime.kotlin.core.Alignment as RiveAlignment
13+
import app.rive.runtime.kotlin.core.errors.*
1314
import kotlinx.coroutines.Dispatchers
1415
import kotlinx.coroutines.withContext
1516

@@ -225,16 +226,14 @@ class HybridRiveView(val context: ThemedReactContext) : HybridRiveViewSpec() {
225226
}
226227

227228
private fun detectErrorType(exception: Exception): RiveErrorType {
228-
val errorMessage = exception.message?.lowercase() ?: ""
229-
230-
return when {
231-
errorMessage.contains("artboard") -> RiveErrorType.INCORRECTARTBOARDNAME
232-
errorMessage.contains("state machine") -> RiveErrorType.INCORRECTSTATEMACHINENAME
233-
errorMessage.contains("animation") -> RiveErrorType.INCORRECTANIMATIONNAME
234-
errorMessage.contains("data binding") || errorMessage.contains("databinding") -> RiveErrorType.DATABINDINGERROR
235-
errorMessage.contains("text run") -> RiveErrorType.TEXTRUNNOTFOUNDERROR
236-
errorMessage.contains("file") || errorMessage.contains("not found") -> RiveErrorType.FILENOTFOUND
237-
errorMessage.contains("malformed") || errorMessage.contains("corrupt") -> RiveErrorType.MALFORMEDFILE
229+
return when (exception) {
230+
is ArtboardException -> RiveErrorType.INCORRECTARTBOARDNAME
231+
is StateMachineException -> RiveErrorType.INCORRECTSTATEMACHINENAME
232+
is AnimationException -> RiveErrorType.INCORRECTANIMATIONNAME
233+
is MalformedFileException -> RiveErrorType.MALFORMEDFILE
234+
is StateMachineInputException -> RiveErrorType.INCORRECTANIMATIONNAME
235+
is TextValueRunException -> RiveErrorType.TEXTRUNNOTFOUNDERROR
236+
is ViewModelException -> RiveErrorType.DATABINDINGERROR
238237
else -> RiveErrorType.UNKNOWN
239238
}
240239
}

ios/HybridRiveView.swift

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,30 +199,36 @@ extension HybridRiveView {
199199

200200
let riveError = RiveError(
201201
message: errorMessage,
202-
type: errorType,
202+
type: errorType
203203
)
204204
onError(riveError)
205205
}
206206
}
207207

208208
private func detectErrorType(_ error: Error) -> RiveErrorType {
209-
let errorDescription = String(describing: error).lowercased()
209+
let nsError = error as NSError
210+
guard let errorName = nsError.userInfo["name"] as? String else {
211+
return .unknown
212+
}
210213

211-
if errorDescription.contains("artboard") {
214+
switch errorName {
215+
case "NoArtboardFound":
212216
return .incorrectartboardname
213-
} else if errorDescription.contains("state machine") {
217+
case "NoStateMachineFound":
214218
return .incorrectstatemachinename
215-
} else if errorDescription.contains("animation") {
219+
case "NoAnimationFound":
216220
return .incorrectanimationname
217-
} else if errorDescription.contains("data binding") || errorDescription.contains("databinding") {
218-
return .databindingerror
219-
} else if errorDescription.contains("text run") {
220-
return .textrunnotfounderror
221-
} else if errorDescription.contains("file") || errorDescription.contains("not found") {
222-
return .filenotfound
223-
} else if errorDescription.contains("malformed") || errorDescription.contains("corrupt") {
221+
case "Malformed":
224222
return .malformedfile
225-
} else {
223+
case "FileNotFound":
224+
return .filenotfound
225+
case "NoStateMachineInputFound":
226+
return .incorrectanimationname
227+
case "TextRunNotFoundError":
228+
return .textrunnotfounderror
229+
case "DataBindingError":
230+
return .databindingerror
231+
default:
226232
return .unknown
227233
}
228234
}

0 commit comments

Comments
 (0)