Handling errors a more generic way