mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-19 06:53:14 +02:00
Remove old getUserInfo function and old API error-handling
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user