       ]
     }
 
-    log = (type, {paymentMethodId, data, operation}) ->
+    logHelper = (type, {paymentMethodId, data, operation}) =>
       if @loggedRequests.test operation
         paymentMethodInfo = if paymentMethodId then "PaymentMethodId: #{paymentMethodId}\n" else ""
         logger[type] "\n#{paymentMethodInfo}Operation: #{operation} \nData: #{data}"  

              else
                errors.push new models.Error err1, err1
            callback errors
            log "error", {paymentMethodId, operation, data: result.errors}
          else
            # Find next page's URL if necessary
            nextUrl = parseNextUrl res  if res.headers.link
            callback null, result, nextUrl
            log "info", {paymentMethodId, operation, data: JSON.stringify(result)}

    req.on 'error', (e)->
      callback [new models.Error 'connection', 'Unable to connect to payment backend.']

        xml2js.parseString body, (err, result)=>
          if err
            callback [new models.Error 'xml', 'Invalid XML']
            logHelper "error",{paymentMethodId, operation, data: err}
          else if result.error
            callback [new models.Error result.error.symbol[0], result.error.description[0]._]
            logHelper "error", {paymentMethodId, operation, data: result.error}
          else if result.errors
            # See https://docs.recurly.com/api/basics/validation-errors for XML format
            errors = []
