Skip to content

Commit

Permalink
mv notAvailableRegexps to class variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tonatoz committed Sep 11, 2024
1 parent 0f1caa6 commit d406bf6
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ abstract class UpstreamRpcMethodsDetector(
) {
protected val log: Logger = LoggerFactory.getLogger(this::class.java)

private val notAvailableRegexps =
listOf(
"method ([A-Za-z0-9_]+) does not exist/is not available",
"([A-Za-z0-9_]+) found but the containing module is disabled",
"Method not found",
"The method ([A-Za-z0-9_]+) is not available",
).map { s -> s.toRegex() }

open fun detectRpcMethods(): Mono<Map<String, Boolean>> = detectByMagicMethod().switchIfEmpty(detectByMethod())

protected fun detectByMethod(): Mono<Map<String, Boolean>> =
Expand All @@ -29,12 +37,7 @@ abstract class UpstreamRpcMethodsDetector(
.map { method to true }
.onErrorResume { err ->
val notAvailableError =
listOf(
"method ([A-Za-z0-9_]+) does not exist/is not available",
"([A-Za-z0-9_]+) found but the containing module is disabled",
"Method not found",
"The method ([A-Za-z0-9_]+) is not available",
).any { s -> s.toRegex().containsMatchIn(err.message ?: "") }
notAvailableRegexps.any { s -> s.containsMatchIn(err.message ?: "") }
if (notAvailableError) {
Mono.just(method to false)
} else {
Expand Down

0 comments on commit d406bf6

Please sign in to comment.