From 32a59e471cd6bc3a4315af5e0511636ceea7f68a Mon Sep 17 00:00:00 2001 From: keremyilmaz Date: Fri, 11 Jul 2025 11:26:02 +0300 Subject: [PATCH] :art: Error handling for Parquet content type files' schema inference is improved for better readability --- .../tofhir/server/service/SchemaDefinitionService.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tofhir-server/src/main/scala/io/tofhir/server/service/SchemaDefinitionService.scala b/tofhir-server/src/main/scala/io/tofhir/server/service/SchemaDefinitionService.scala index 712a7eef..11e31b5b 100644 --- a/tofhir-server/src/main/scala/io/tofhir/server/service/SchemaDefinitionService.scala +++ b/tofhir-server/src/main/scala/io/tofhir/server/service/SchemaDefinitionService.scala @@ -130,8 +130,13 @@ class SchemaDefinitionService(schemaRepository: ISchemaRepository, mappingReposi .limit(1) // It is enough to take the first row to infer the schema. } catch { case e: FhirMappingException => - // Remove the new lines and capitalize the error detail to show it in front-end properly. - throw BadRequest(e.getMessage, e.getCause.toString.capitalize.replace("\n", " ")) + val simplifiedCause = Option(e.getCause).map(_.getMessage).map(_.replace("\n", " ")).getOrElse("") + val detail = + if (simplifiedCause.toLowerCase.contains("parquet") && simplifiedCause.toLowerCase.contains("not a parquet file")) + "Content type mismatch: the input file is not a valid Parquet file." + else + simplifiedCause.capitalize + throw BadRequest(e.getMessage, detail) } dataFrame.schema // Get the schema inferred by Spark }