diff --git a/mpp-pay.js b/mpp-pay.js index 14ca5e1..9d7f4a2 100644 --- a/mpp-pay.js +++ b/mpp-pay.js @@ -266,6 +266,7 @@ function createMppPay({ secret, realm, recipient, routes, facilitator, tempo = n } function refuse(req, res, route, reason) { + res.locals.mppRefused = String(reason).slice(0, 160); // for the usage log: why the credential was refused res.status(402); res.set('WWW-Authenticate', headersFor(route)); res.set('Cache-Control', 'no-store'); diff --git a/usage-log.js b/usage-log.js index 851adaf..1813e26 100644 --- a/usage-log.js +++ b/usage-log.js @@ -264,7 +264,7 @@ function createUsageLog({ service, env = process.env, fetchFn = globalThis.fetch ms: Date.now() - started, paid: Boolean(payment), ...(payment || {}), - ...(quote ? { quote: true, ...(offered ? { payment_failed: true, ...(mppOffered ? { protocol: 'mpp' } : {}), ...(attemptedNetwork(req) ? { network: attemptedNetwork(req) } : {}) } : {}) } : {}), + ...(quote ? { quote: true, ...(offered ? { payment_failed: true, ...(mppOffered ? { protocol: 'mpp', ...(res.locals && res.locals.mppRefused ? { reason: res.locals.mppRefused } : {}) } : {}), ...(attemptedNetwork(req) ? { network: attemptedNetwork(req) } : {}) } : {}) } : {}), agent: agentOf(req.headers['user-agent']), visitor: visitorOf(req.ip || (req.socket && req.socket.remoteAddress), visitorSecret), input: described.input,