mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-15 09:06:25 +00:00
4f59b62da4
* chore(deps): update dependency prettier to v2 * Run prettier-fix Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Jamie Magee <jamie.magee@gmail.com>
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import is from '@sindresorhus/is';
|
|
|
|
Error.stackTraceLimit = 20;
|
|
|
|
// TODO: remove any type
|
|
export default function errSerializer(err: any): any {
|
|
const response = {
|
|
...err,
|
|
};
|
|
if (err.body) {
|
|
response.body = err.body;
|
|
} else if (err.response && err.response.body) {
|
|
response.body = err.response.body;
|
|
}
|
|
if (err.message) {
|
|
response.message = err.message;
|
|
}
|
|
if (err.stack) {
|
|
response.stack = err.stack;
|
|
}
|
|
if (response.gotOptions) {
|
|
if (is.string(response.gotOptions.auth)) {
|
|
response.gotOptions.auth = response.gotOptions.auth.replace(
|
|
/:.*/,
|
|
':***********'
|
|
);
|
|
}
|
|
if (err.gotOptions.headers) {
|
|
const redactedHeaders = [
|
|
'authorization',
|
|
'private-header',
|
|
'Private-header',
|
|
];
|
|
redactedHeaders.forEach((header) => {
|
|
if (response.gotOptions.headers[header]) {
|
|
response.gotOptions.headers[header] = '** redacted **';
|
|
}
|
|
});
|
|
}
|
|
}
|
|
const redactedFields = ['message', 'stack', 'stdout', 'stderr'];
|
|
for (const field of redactedFields) {
|
|
if (is.string(response[field])) {
|
|
response[field] = response[field].replace(
|
|
/https:\/\/[^@]*@/g,
|
|
'https://**redacted**@'
|
|
);
|
|
}
|
|
}
|
|
return response;
|
|
}
|