Fix badcondition mapping (#361)

Co-authored-by: Florent Champigny <florent@bere.al>
This commit is contained in:
Florent CHAMPIGNY 2025-10-18 08:35:46 +02:00 committed by GitHub
parent 26daf23c6d
commit 3380d2f477
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View file

@ -1,5 +1,6 @@
package io.github.openflocon.flocon.plugins.network.model
import io.github.openflocon.flocon.FloconLogger
import kotlin.random.Random
data class BadQualityConfig(
@ -36,8 +37,13 @@ data class BadQualityConfig(
val classPath: String,
) : Type {
fun generate() : Throwable? {
val errorClass = Class.forName(classPath)
return errorClass.newInstance() as? Throwable
return try {
val errorClass = Class.forName(classPath)
errorClass.newInstance() as? Throwable
} catch (t: Throwable) {
FloconLogger.logError("BadQualityConfig error, className not found", t)
null
}
}
}
}

View file

@ -68,7 +68,7 @@ fun parseBadQualityConfig(jsonString: String): BadQualityConfig? {
val errorContentType = errorObject.optString("errorContentType")
val error = BadQualityConfig.Error(
weight = errorObject.getDouble("weight").toFloat(),
type = if (errorException.isNotEmpty()) {
type = if (errorException.isNotEmpty() && errorException != "null") {
BadQualityConfig.Error.Type.ErrorThrow(errorException)
} else {
BadQualityConfig.Error.Type.Body(