Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkondratek committed Jul 30, 2024
1 parent 3fb7a82 commit e69f21d
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ sealed class SourcegraphApiRequest<out T>(val url: String) {
return SourcegraphApiContentHelper.toJson(request, true)
}

private fun throwException(errors: List<GraphQLErrorDTO>): Nothing {
if (errors.size == 1) throw SourcegraphConfusingException(errors.single().toString())
throw SourcegraphConfusingException(errors.toString())
}

override fun extractResult(response: SourcegraphApiResponse): T {
val result: GraphQLResponseDTO<out T, GraphQLErrorDTO> =
response.readBody {
Expand All @@ -52,8 +47,13 @@ sealed class SourcegraphApiRequest<out T>(val url: String) {
if (data != null) return data

val errors = result.errors
if (errors == null) error("Undefined request state - both result and errors are null")
else throwException(errors)
when {
errors == null ->
throw SourcegraphConfusingException(
"Undefined request state - both result and errors are null")
errors.size == 1 -> throw SourcegraphConfusingException(errors.single().toString())
else -> throw SourcegraphConfusingException(errors.toString())
}
}
}
}
Expand Down

0 comments on commit e69f21d

Please sign in to comment.