spring-projects / spring-hateoas

Spring HATEOAS - Library to support implementing representations for hyper-text driven REST web services.
https://spring.io/projects/spring-hateoas
Apache License 2.0
1.03k stars 475 forks source link

Traverson to provide more meaningful exception when link doesn't exist #539

Open Kerruba opened 7 years ago

Kerruba commented 7 years ago

At the moment an IllegalStateException is thrown when traverson doesn't find a link with the rel you specified. What about provide a more meaningful exception, like LinkNotFoundException or similar?

gregturn commented 7 years ago

The message is quite detailed:

java.lang.IllegalStateException: Expected to find link with rel 'foo' in response {
  "_links" : {
    "items" : {
      "href" : "http://localhost:52758/springagram/items{?projection}",
      "templated" : true
    },
    "profile" : {
      "href" : "http://localhost:52758/springagram/alps"
    }
  }
}
!

Are you suggesting you want to trap this type of exception across the framework? Because that sounds like an API adjustment to define a new exception for this condition.

gregturn commented 7 years ago

I wanted to get @olivergierke 's opinion on this. It would appear to generate a more typesafe manner of no link being found. But since this is exception handler, it also promotes using exceptions for controls.

I have attached a commit on an experimental branch.

Kerruba commented 7 years ago

Yeah I would say this way the exception is more context related. Thanks