Draft: Adding Type Safe errors matched to response codes

This MR is a proposal to add an error type to Endpoint, and make it so the server route returns an Either<Failure,Success> and the client returns an either too.

Right now it puts the whole mapping of object to status code in the common definition (the classes extending Resource), and the idea is that the server matches the actual returned type to the successMap to find the correct status code, and the client does the opposite, it gets the status code returns the correct response after possibly having parsed the body.

For now it works, however the case I added to use a "simple" return type, without a sealed class can run into issues, currently in the server tests, the success return type is defined as a List, but then the actual routing returns an ArrayList so obviously it fails to find a match because it wants the exact same class.

To solve this it would require to have a special case for a single success type where it would maybe always be picked ? Or maybe another overload for .response() that would only take a single class.

It would also maybe be useful to split the .response() into .success() and .failure().

ALso, right now nothing prevents the user from putting the same status code in the failure and success maps

Edited by LelouBil

Merge request reports

Loading