Better error handling + new expectedStatusCode parameter to check the http status code on the response