I am using dartz package to return different types from a method, but the problem is I can't return an exception. here is the code below:
class CatPhotoApi {
String endpoint = 'api.thecatapi.com';
Future<Either<Exception, Map<String, dynamic>>> getRandomCatPhoto() async {
try {
final queryParameters = {
"api_key": "example key",
};
final uri = Uri.https(endpoint, "/v1/images/search", queryParameters);
final response = await http.get(uri);
return Right(response.body as Map<String, dynamic>);
} catch (e) {
// The error occurs here:
return Left(e as Exception);
}
}
}