Handle null objects gracefully in ApiRequest.cleanup()