HEX
Server: Apache
System: Linux srv4.garantili.com.tr 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: yenicep (1023)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home2/yenicep/garantili-kasko/node_modules/auth0/src/errors.js
const util = require('util');

const errors = (module.exports = {});

const sanitizeErrors = function (collection) {
  if (!collection) {
    return;
  }

  Object.keys(collection).forEach((key) => {
    if (key.toLowerCase().match('password|secret|authorization')) {
      collection[key] = '[REDACTED]';
    }
  });
};

/**
 * Given a response request error, sanitize sensitive data.
 *
 * @param {Error} error Error object
 * @returns {Error}
 */
errors.sanitizeErrorRequestData = function (error) {
  if (
    !error.response ||
    !error.response.request ||
    (!error.response.request._data && !error.response.request._header)
  ) {
    return error;
  }

  sanitizeErrors(error.response.request._header);
  sanitizeErrors(error.response.request._data);

  return error;
};

/**
 * Given an Api Error, modify the original error and sanitize
 * sensitive information using sanitizeErrorRequestData
 *
 * @param {string} name New error name
 * @param {string} message New error message
 * @param {number} status New error status
 * @param {any} requestInfo Request info to be attached on the error
 * @param {any} originalError Original error to be attached on the error
 */
const SanitizedError = function (name, message, status, requestInfo, originalError) {
  this.name = name || this.constructor.name || this.constructor.prototype.name || '';
  this.message = message || '';
  this.statusCode = status || (originalError && originalError.code);
  this.requestInfo = Object.assign({}, requestInfo);
  this.originalError = errors.sanitizeErrorRequestData(originalError);

  Error.captureStackTrace(this, this.constructor);
};

util.inherits(SanitizedError, Error);

errors.SanitizedError = SanitizedError;