Closed hendryluk closed 9 years ago
This should also support generics and constraint resolutions. E.g.:
public void OnInvalidEntities<T>(
[HandlesException] InvalidEntityException<T> e,
IRepository<T> repo) // <- whatever additional dependencies
where T: IAuditable // <- constraints
{
/* handles */
}
(This is not part of CDI spec or Jboss Weld, since java doesn't have true generics)
This has now been implemented.
The [ExceptionHandled] attribute can also be used on properties as well as on the class level (in this case: the MyComponent class).
Cormo.Web comes with exception support as the following:
For example:
Or could be shorten into:
Then you can throw that exception (MyNotFoundException) from anywhere within your application, and the framework will return 404 (NotFound) response.
The latter approach is a great way to create declaratively map exception types with http status codes, i.e. by having an exception-mapping class that contains a bunch of these declarative exception-handler methods.