Files
pulse-signage/src/web/pages/error.js
T
2026-07-25 02:29:19 +01:00

63 lines
2.2 KiB
JavaScript

const { renderView } = require('../view');
function getErrorCopy(statusCode, message) {
const normalizedStatusCode = Number(statusCode) || 500;
if (normalizedStatusCode === 403) {
return {
title: 'Access denied',
errorTitle: 'Access denied',
errorMessage: message || 'You do not have permission to access this area.',
backLabel: 'Back to dashboard'
};
}
if (normalizedStatusCode === 404) {
return {
title: 'Not found',
errorTitle: 'Oops! Page not found.',
errorMessage: message || 'We could not find the page you were looking for. Meanwhile, you may return to the dashboard or try searching for what you need.',
backLabel: 'Back to dashboard'
};
}
if (normalizedStatusCode >= 500) {
return {
title: 'Something went wrong',
errorTitle: 'Something went wrong.',
errorMessage: message || 'An unexpected error occurred. Please try again in a moment.',
backLabel: 'Back to dashboard'
};
}
return {
title: 'Error',
errorTitle: 'Error',
errorMessage: message || 'An unexpected error occurred.',
backLabel: 'Back to dashboard'
};
}
module.exports = function renderErrorPage(options, currentUser) {
const errorOptions = options || {};
const statusCode = Number(errorOptions.statusCode || 500);
const copy = getErrorCopy(statusCode, String(errorOptions.message || '').trim());
return renderView('error/error', {
title: String(errorOptions.title || copy.title || 'Error').trim(),
active: '',
messageVariant: 'primary',
currentUser: currentUser || null,
statusCode: statusCode,
errorTitle: String(errorOptions.errorTitle || copy.errorTitle || errorOptions.title || 'Error').trim(),
errorMessage: String(errorOptions.message || copy.errorMessage || 'An unexpected error occurred.').trim(),
detail: String(errorOptions.detail || '').trim(),
backUrl: String(errorOptions.backUrl || '/dashboard').trim() || '/dashboard',
backLabel: String(errorOptions.backLabel || copy.backLabel || 'Back to dashboard').trim() || 'Back to dashboard',
searchUrl: String(errorOptions.searchUrl || '').trim(),
bodyClass: 'error-page bg-dark text-white',
errorShell: true,
stylesheets: [],
scripts: []
});
};