Skip to content

Commit

Permalink
throw exception in client call
Browse files Browse the repository at this point in the history
Signed-off-by: Kaituo Li <[email protected]>
  • Loading branch information
kaituo committed Oct 17, 2023
1 parent 0254bbf commit 576f3bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,14 @@ object FlintJob extends Logging {
} catch {
case e: IllegalStateException
if e.getCause().getMessage().contains("index_not_found_exception") =>
osClient.createIndex(resultIndex, mapping) match {
case Right(_) => Right(())
case Left(errorMsg) => Left(errorMsg)
try {
osClient.createIndex(resultIndex, mapping)
Right(())
} catch {
case e: Exception =>
val error = s"Failed to create result index $resultIndex"
logError(error, e)
Left(error)
}
case e: Exception =>
val error = "Failed to verify existing mapping"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class OSClient(val flintOptions: FlintOptions) extends Logging {
* use Either for representing success or failure. A Right value indicates success, while a
* Left value indicates an error.
*/
def createIndex(osIndexName: String, mapping: String): Either[String, Unit] = {
def createIndex(osIndexName: String, mapping: String): Unit = {
logInfo(s"create $osIndexName")

using(FlintClientBuilder.build(flintOptions).createClient()) { client =>
Expand All @@ -52,12 +52,9 @@ class OSClient(val flintOptions: FlintOptions) extends Logging {
try {
client.indices.create(request, RequestOptions.DEFAULT)
logInfo(s"create $osIndexName successfully")
Right(())
} catch {
case e: Exception =>
val error = s"Failed to create result index $osIndexName"
logError(error, e)
Left(error)
throw new IllegalStateException(s"Failed to create index $osIndexName", e);
}
}
}
Expand Down

0 comments on commit 576f3bf

Please sign in to comment.