HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/LC/api/utils/axios.js
const { logger } = require('~/config');

/**
 * Logs Axios errors based on the error object and a custom message.
 *
 * @param {Object} options - The options object.
 * @param {string} options.message - The custom message to be logged.
 * @param {Error} options.error - The Axios error object.
 */
const logAxiosError = ({ message, error }) => {
  const timedOutMessage = 'Cannot read properties of undefined (reading \'status\')';
  if (error.response) {
    logger.error(
      `${message} The request was made and the server responded with a status code that falls out of the range of 2xx: ${
        error.message ? error.message : ''
      }. Error response data:\n`,
      {
        headers: error.response?.headers,
        status: error.response?.status,
        data: error.response?.data,
      },
    );
  } else if (error.request) {
    logger.error(
      `${message} The request was made but no response was received: ${
        error.message ? error.message : ''
      }. Error Request:\n`,
      {
        request: error.request,
      },
    );
  } else if (error?.message?.includes(timedOutMessage)) {
    logger.error(
      `${message}\nThe request either timed out or was unsuccessful. Error message:\n`,
      error,
    );
  } else {
    logger.error(
      `${message}\nSomething happened in setting up the request. Error message:\n`,
      error,
    );
  }
};

module.exports = { logAxiosError };