MCPcopy
hub / github.com/axios/axios / redactConfig

Function redactConfig

lib/core/AxiosError.js:29–73  ·  view source on GitHub ↗
(config, redactKeys)

Source from the content-addressed store, hash-verified

27// (case-insensitive) listed in `redactKeys` with REDACTED. Walks through arrays
28// and AxiosHeaders, and short-circuits on circular references.
29function redactConfig(config, redactKeys) {
30 const lowerKeys = new Set(redactKeys.map((k) => String(k).toLowerCase()));
31 const seen = [];
32
33 const visit = (source) => {
34 if (source === null || typeof source !== 'object') return source;
35 if (utils.isBuffer(source)) return source;
36 if (seen.indexOf(source) !== -1) return undefined;
37
38 if (source instanceof AxiosHeaders) {
39 source = source.toJSON();
40 }
41
42 seen.push(source);
43
44 let result;
45 if (utils.isArray(source)) {
46 result = [];
47 source.forEach((v, i) => {
48 const reducedValue = visit(v);
49 if (!utils.isUndefined(reducedValue)) {
50 result[i] = reducedValue;
51 }
52 });
53 } else {
54 if (!utils.isPlainObject(source) && hasOwnOrPrototypeToJSON(source)) {
55 seen.pop();
56 return source;
57 }
58
59 result = Object.create(null);
60 for (const [key, value] of Object.entries(source)) {
61 const reducedValue = lowerKeys.has(key.toLowerCase()) ? REDACTED : visit(value);
62 if (!utils.isUndefined(reducedValue)) {
63 result[key] = reducedValue;
64 }
65 }
66 }
67
68 seen.pop();
69 return result;
70 };
71
72 return visit(config);
73}
74
75class AxiosError extends Error {
76 static from(error, code, config, request, response, customProps) {

Callers 1

toJSONMethod · 0.85

Calls 1

visitFunction · 0.70

Tested by

no test coverage detected