Logging and redaction
Use case
Log request and response details for debugging, with sensitive headers automatically redacted.
Request/response logging interceptor
import { createClient } from '@parcely/core'
const http = createClient({ baseURL: 'https://api.example.com' })
http.interceptors.request.use((config) => {
console.log(`--> ${config.method ?? 'GET'} ${config.url}`)
return config
})
http.interceptors.response.use(
(response) => {
console.log(`<-- ${response.status} ${response.config.url}`)
return response
},
(err) => {
console.error(`<-- ERROR ${err}`)
throw err
},
)
Automatic redaction
parcely automatically redacts sensitive header values in:
- The
configfield ofHttpResponseenvelopes - The
configfield ofHttpErrorobjects
By default, the following headers are redacted (values replaced with '[REDACTED]'):
authorizationcookieproxy-authorizationset-cookiex-api-key
Custom sensitive headers
const http = createClient({
baseURL: 'https://api.example.com',
sensitiveHeaders: [
'authorization',
'cookie',
'proxy-authorization',
'set-cookie',
'x-api-key',
'x-secret-token', // add your own
],
})
Axios equivalent
Axios does not redact sensitive headers in errors or responses. In parcely, redaction is built in.
Notes and gotchas
- Redaction applies to the
configattached to responses and errors. It does not affect the actual headers sent in the request. - Request interceptors see the live, un-redacted config. This is intentional -- interceptors need full access to set headers.
- The
sensitiveHeadersoption is case-insensitive. - Setting
sensitiveHeadersreplaces the default list entirely. Include the defaults if you want to extend rather than replace.