in graphql-dgs-spring-boot-micrometer/src/main/kotlin/com/netflix/graphql/dgs/metrics/micrometer/DgsGraphQLMetricsInstrumentation.kt [409:444]
fun sanitizeErrorPaths(errors: List<GraphQLError>): Collection<ErrorTagValues> {
val dedupeErrorPaths = mutableMapOf<String, ErrorTagValues>()
errors.forEach { error ->
val errorPath: List<Any>
val errorType: String
val errorDetail = errorDetailExtension(error)
when (error) {
is ValidationError -> {
errorPath = error.queryPath.orEmpty()
errorType = ErrorType.BAD_REQUEST.name
}
is InvalidSyntaxError -> {
errorPath = emptyList()
errorType = ErrorType.BAD_REQUEST.name
}
else -> {
errorPath = error.path.orEmpty()
errorType = errorTypeExtension(error)
}
}
val path =
errorPath.joinToString(prefix = "[", postfix = "]") { segment ->
when (segment) {
is Number -> "number"
is String -> segment
else -> segment.toString()
}
}
dedupeErrorPaths.computeIfAbsent(path) {
ErrorTagValues(path, errorType, errorDetail)
}
}
return dedupeErrorPaths.values
}