mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00

* refactor: Ensure Axios Errors are less Verbose if No Response * refactor: Improve error handling in logAxiosError function * fix: Prevent ModelSelect from rendering for Agent Endpoints * refactor: Enhance logging functions with type parameter for better clarity * refactor: Update buildDefaultConvo function to use optional endpoint parameter since we pass a default value for undefined * refactor: Replace console logs with logger warnings and errors in useNavigateToConvo hook, and handle removed endpoint edge case * chore: import order
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
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 {import('axios').AxiosError} options.error - The Axios error object.
|
|
*/
|
|
const logAxiosError = ({ message, error }) => {
|
|
try {
|
|
if (error.response?.status) {
|
|
const { status, headers, data } = error.response;
|
|
logger.error(`${message} The server responded with status ${status}: ${error.message}`, {
|
|
status,
|
|
headers,
|
|
data,
|
|
});
|
|
} else if (error.request) {
|
|
const { method, url } = error.config || {};
|
|
logger.error(
|
|
`${message} No response received for ${method ? method.toUpperCase() : ''} ${url || ''}: ${error.message}`,
|
|
{ requestInfo: { method, url } },
|
|
);
|
|
} else if (error?.message?.includes('Cannot read properties of undefined (reading \'status\')')) {
|
|
logger.error(
|
|
`${message} It appears the request timed out or was unsuccessful: ${error.message}`,
|
|
);
|
|
} else {
|
|
logger.error(`${message} An error occurred while setting up the request: ${error.message}`);
|
|
}
|
|
} catch (err) {
|
|
logger.error(`Error in logAxiosError: ${err.message}`);
|
|
}
|
|
};
|
|
|
|
module.exports = { logAxiosError };
|