Closed SerVB closed 4 years ago
@Response
is resolved during initialisation (No reflection during runtime in this library) on the generic type you specify in the generic parameters. Here it is IResponse which is not annotated.
The way to handle this is to respond the goodresponse directly or throw a NotFound exception that you catch with a throw handler on the route that responds 404.
Exceptions are the design choice because exceptions are more maintainable if you have endpoints who call services that can fail. The services then just have to throw a handled exception without having to worry about responding it properly, which reduces the possibility of bugs in the long run.
Hi! I don't understand how to respond with a custom status code, for example, 404, depending on the situation.
I try the following: I declare an interface and set it as a response type. Then I create some children of the interface with specified status codes. Example:
I want to see 404, but it's 200:
Is it supported now?
If you want to take a look a real-world example, please fresh start this revision of my project and call GET http://localhost:8080/v1/product/0, the status should be 404 but it returns OK and this test fails: https://github.com/SerVB/e-shop/blob/37958c8bb4fee8a42dad229c578f79867c1b5d74/server/src/test/kotlin/io/github/servb/eShop/product/route/singleOperation/EShopProductReturnProductTest.kt .