Remove old getUserInfo function and old API error-handling

This commit is contained in:
2026-02-15 22:49:32 +01:00
parent 35a8e0228d
commit a98095581a
2 changed files with 63 additions and 126 deletions

View File

@@ -1,6 +1,11 @@
// API helper functions for Fail2ban UI
// API helpers for Fail2ban UI.
"use strict";
// Add server parameter to URL
// =========================================================================
// Server-Scoped Requests
// =========================================================================
// Adds the server ID to the URL if a server is selected.
function withServerParam(url) {
if (!currentServerId) {
return url;
@@ -8,7 +13,7 @@ function withServerParam(url) {
return url + (url.indexOf('?') === -1 ? '?' : '&') + 'serverId=' + encodeURIComponent(currentServerId);
}
// Get server headers for API requests
// Adds the server ID to the headers if a server is selected.
function serverHeaders(headers) {
headers = headers || {};
if (currentServerId) {
@@ -16,28 +21,3 @@ function serverHeaders(headers) {
}
return headers;
}
// Auth-aware fetch wrapper that handles 401/403 responses
function authFetch(url, options) {
options = options || {};
// Ensure Accept header for API requests
if (!options.headers) {
options.headers = {};
}
if (!options.headers['Accept']) {
options.headers['Accept'] = 'application/json';
}
return fetch(url, options).then(function(response) {
// Handle authentication errors
if (response.status === 401 || response.status === 403) {
if (typeof handleAuthError === 'function') {
handleAuthError(response);
}
// Return a rejected promise to stop the chain
return Promise.reject(new Error('Authentication required'));
}
return response;
});
}