Improved api requests to handle server errors by checking http code and throwing exception