From a8f84c75dde093b69b84de4bd6f3468825b10563 Mon Sep 17 00:00:00 2001 From: Simon Dumas Date: Wed, 10 Apr 2024 10:29:38 +0200 Subject: [PATCH] Improve message for 'ResourceShaclEngineRejection' --- .../sdk/resources/ValidateResource.scala | 2 +- .../resources/model/ResourceRejection.scala | 31 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/ValidateResource.scala b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/ValidateResource.scala index 4b84959c68..a1ba842ebd 100644 --- a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/ValidateResource.scala +++ b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/ValidateResource.scala @@ -84,7 +84,7 @@ object ValidateResource { schema.value.shapes, reportDetails = true ).adaptError { e => - ResourceShaclEngineRejection(jsonld.id, schemaRef, e.getMessage) + ResourceShaclEngineRejection(jsonld.id, schemaRef, e) }.span("validateShacl") private def assertNotDeprecated(schema: ResourceF[Schema]) = { diff --git a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/model/ResourceRejection.scala b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/model/ResourceRejection.scala index 9412957c02..ffd7974560 100644 --- a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/model/ResourceRejection.scala +++ b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/model/ResourceRejection.scala @@ -160,8 +160,10 @@ object ResourceRejection { * @param details * the SHACL engine errors */ - final case class ResourceShaclEngineRejection(id: Iri, schema: ResourceRef, details: String) - extends ResourceRejection(s"Resource '$id' failed to produce a SHACL engine for schema '$schema'.") + final case class ResourceShaclEngineRejection(id: Iri, schema: ResourceRef, cause: Throwable) + extends ResourceRejection( + s"${ClassUtils.simpleName(cause)}: The SHACL engine could not be instantiated for resource '$id' and schema '$schema'." + ) /** * Rejection returned when attempting to update/deprecate a resource that is already deprecated. @@ -211,13 +213,13 @@ object ResourceRejection { val tpe = ClassUtils.simpleName(r) val obj = JsonObject.empty.add(keywords.tpe, tpe.asJson).add("reason", r.reason.asJson) r match { - case ResourceShaclEngineRejection(_, _, details) => obj.add("details", details.asJson) - case InvalidResource(_, _, report, expanded) => + case ResourceShaclEngineRejection(_, _, cause) => obj.add("details", cause.getMessage.asJson) + case InvalidResource(_, _, report, expanded) => obj.addContext(contexts.shacl).add("details", report.json).add("expanded", expanded.json) - case InvalidSchemaRejection(_, _, report) => + case InvalidSchemaRejection(_, _, report) => obj.addContext(contexts.resolvers).add("report", report.asJson) - case IncorrectRev(provided, expected) => obj.add("provided", provided.asJson).add("expected", expected.asJson) - case _ => obj + case IncorrectRev(provided, expected) => obj.add("provided", provided.asJson).add("expected", expected.asJson) + case _ => obj } } @@ -226,12 +228,13 @@ object ResourceRejection { implicit val responseFieldsResources: HttpResponseFields[ResourceRejection] = HttpResponseFields { - case RevisionNotFound(_, _) => StatusCodes.NotFound - case ResourceNotFound(_, _) => StatusCodes.NotFound - case TagNotFound(_) => StatusCodes.NotFound - case InvalidSchemaRejection(_, _, _) => StatusCodes.NotFound - case ResourceAlreadyExists(_, _) => StatusCodes.Conflict - case IncorrectRev(_, _) => StatusCodes.Conflict - case _ => StatusCodes.BadRequest + case RevisionNotFound(_, _) => StatusCodes.NotFound + case ResourceNotFound(_, _) => StatusCodes.NotFound + case TagNotFound(_) => StatusCodes.NotFound + case InvalidSchemaRejection(_, _, _) => StatusCodes.NotFound + case ResourceShaclEngineRejection(_, _, _) => StatusCodes.InternalServerError + case ResourceAlreadyExists(_, _) => StatusCodes.Conflict + case IncorrectRev(_, _) => StatusCodes.Conflict + case _ => StatusCodes.BadRequest } }