Skip to content

Commit

Permalink
Don't mention the schema when returning ResourceNotFound: it isn't af…
Browse files Browse the repository at this point in the history
…fected by the schema (#4372)
  • Loading branch information
shinyhappydan authored Oct 17, 2023
1 parent 5c3ec3d commit e65a47c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ResourcesTrialRoutesSpec extends BaseRouteSpec with ResourceInstanceFixtur
// Returns no validation result for myId for `schemas.resources`
case (StringSegment("myId") | IriSegment(`myId`), Some(IriSegment(schemas.resources))) =>
UIO.pure(NoValidation(projectRef))
case (IriSegment(iri), None) => IO.raiseError(ResourceNotFound(iri, project, None))
case (IriSegment(iri), None) => IO.raiseError(ResourceNotFound(iri, project))
case _ => IO.terminate(new IllegalStateException("Should not happen !"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ object Resources {
def stateWhereResourceExists(c: ModifyCommand) = {
state match {
case None =>
IO.raiseError(ResourceNotFound(c.id, c.project, c.schemaOpt))
IO.raiseError(ResourceNotFound(c.id, c.project))
case Some(s) if s.rev != c.rev =>
IO.raiseError(IncorrectRev(c.rev, s.rev))
case Some(s) if c.schemaOpt.exists(cur => cur.iri != s.schema.iri) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ final class ResourcesImpl private (
projectContext <- fetchContext.onModify(projectRef)
iri <- expandIri(id, projectContext)
schemaRefOpt <- expandResourceRef(schemaOpt, projectContext)
resource <- log.stateOr(projectRef, iri, ResourceNotFound(iri, projectRef, schemaRefOpt))
resource <- log.stateOr(projectRef, iri, ResourceNotFound(iri, projectRef))
jsonld <- sourceParser(projectRef, projectContext, iri, resource.source)
res <- eval(RefreshResource(iri, projectRef, schemaRefOpt, jsonld, resource.rev, caller))
} yield res
Expand Down Expand Up @@ -145,7 +145,7 @@ final class ResourcesImpl private (
pc <- fetchContext.onRead(projectRef)
iri <- expandIri(id.value, pc)
schemaRefOpt <- expandResourceRef(schemaOpt, pc)
notFound = ResourceNotFound(iri, projectRef, schemaRefOpt)
notFound = ResourceNotFound(iri, projectRef)
state <- id match {
case Latest(_) => log.stateOr(projectRef, iri, notFound)
case Revision(_, rev) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ object ResourceRejection {
* the resource identifier
* @param project
* the project it belongs to
* @param schemaOpt
* the optional schema reference
*/
final case class ResourceNotFound(id: Iri, project: ProjectRef, schemaOpt: Option[ResourceRef])
final case class ResourceNotFound(id: Iri, project: ProjectRef)
extends ResourceFetchRejection(
s"Resource '$id' not found${schemaOpt.fold("")(schema => s" with schema '$schema'")} in project '$project'."
s"Resource '$id' not found in project '$project'."
)

/**
Expand Down Expand Up @@ -240,7 +238,7 @@ object ResourceRejection {
implicit val responseFieldsResources: HttpResponseFields[ResourceRejection] =
HttpResponseFields {
case RevisionNotFound(_, _) => StatusCodes.NotFound
case ResourceNotFound(_, _, _) => StatusCodes.NotFound
case ResourceNotFound(_, _) => StatusCodes.NotFound
case TagNotFound(_) => StatusCodes.NotFound
case InvalidSchemaRejection(_, _, _) => StatusCodes.NotFound
case ProjectContextRejection(rej) => rej.status
Expand Down

0 comments on commit e65a47c

Please sign in to comment.