added defer to log statement to properly capture response state