Return Error object for failed Api requests and fixed flaky test.

Why are we changing this line? User should be able to obtain all available info about the error.