added better error handling for non 200 status codes