Remove the Class parameter from the method signature: The implementation must know the instance type.
Using a proper class to represent an API response with an error.
A new view to display error messages.
Parse JSON nodes as generic types. Using the factory method and singleton patterns.
Using an handler to verify the responses coming from API requests. Return an instance of a class that can transform the response body as a generic type. Throw a specific exception if the response has an error, handling it as described in the docs.