File size: 7,850 Bytes
683a499
 
64c9a90
683a499
 
 
1bc6b84
 
683a499
 
 
1bc6b84
683a499
 
 
 
 
1bc6b84
 
 
683a499
 
1bc6b84
683a499
 
 
 
1bc6b84
 
 
 
683a499
 
1bc6b84
cb9e543
 
 
 
 
1bc6b84
 
 
 
 
 
cb9e543
 
1bc6b84
cb9e543
 
1bc6b84
 
 
 
 
 
683a499
 
 
 
 
 
 
 
01e8cf0
683a499
 
01e8cf0
 
683a499
 
01e8cf0
 
 
 
 
 
 
 
 
 
 
683a499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91081ff
683a499
 
 
91081ff
b1c16da
 
 
683a499
 
91081ff
 
 
 
 
 
 
 
 
 
 
 
 
683a499
 
28fa7d6
683a499
28fa7d6
683a499
 
 
 
 
28fa7d6
683a499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bc6b84
683a499
 
 
 
01e8cf0
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Sample data - in a real app this would come from an API
const sampleLogs = [
    {
        id: 1,
        status: 500,
        method: 'POST',
        time: '2023-05-15 14:32:45',
        url: 'https://api.example.com/v1/users',
        errorMessage: 'Internal Server Error: Database connection timeout',
        errorCode: 'DB_CONN_TIMEOUT',
        errorType: 'Database',
        resolution: 'Check database connection pool. Verify database server is running and accessible. Consider increasing connection timeout setting.'
    },
    {
        id: 2,
        status: 404,
        method: 'GET',
        time: '2023-05-15 14:30:12',
        url: 'https://api.example.com/v1/products/12345',
        errorMessage: 'Product not found with ID 12345',
        errorCode: 'RESOURCE_NOT_FOUND',
        errorType: 'Validation',
        resolution: 'Verify the product ID exists in the database. Check if the product was deleted. Validate the request parameters.'
    },
    {
        id: 3,
        status: 400,
        method: 'PUT',
        time: '2023-05-15 14:25:33',
        url: 'https://api.example.com/v1/orders/678',
        errorMessage: 'Invalid request body: Missing required field "quantity"',
        errorCode: 'VALIDATION_ERROR',
        errorType: 'Validation',
        resolution: 'Check the API documentation for required fields. Validate the request body before sending. Ensure all required fields are included.'
    },
    {
        id: 4,
        status: 401,
        method: 'GET',
        time: '2023-05-15 14:20:18',
        url: 'https://api.example.com/v1/users/me',
        errorMessage: 'Unauthorized: Invalid or expired access token',
        errorCode: 'INVALID_TOKEN',
        errorType: 'Authentication',
        resolution: 'Check if the access token is valid and not expired. Verify the token signature. Refresh the token if needed.'
    },
    {
        id: 5,
        status: 503,
        method: 'POST',
        time: '2023-05-15 14:15:42',
        url: 'https://api.example.com/v1/payments',
        errorMessage: 'Service Unavailable: Payment gateway not responding',
        errorCode: 'GATEWAY_TIMEOUT',
        errorType: 'Integration',
        resolution: 'Check the payment gateway status. Verify network connectivity. Implement retry logic with exponential backoff.'
    }
];
// DOM elements
const logsTable = document.getElementById('logsTable');
const errorModal = document.getElementById('errorModal');
const closeModal = document.getElementById('closeModal');
const closeModalBtn = document.getElementById('closeModalBtn');
const submitTicket = document.getElementById('submitTicket');
const searchInput = document.querySelector('input[type="text"]');
// Current selected log
let currentLog = null;
// Function to render logs table with optional filter
function renderLogsTable(filter = '') {
    logsTable.innerHTML = '';
    
    const filteredLogs = filter 
        ? sampleLogs.filter(log => 
            log.url.toLowerCase().includes(filter.toLowerCase()) || 
            log.errorMessage.toLowerCase().includes(filter.toLowerCase()) ||
            log.status.toString().includes(filter) ||
            log.method.toLowerCase().includes(filter.toLowerCase())
        )
        : sampleLogs;
    
    filteredLogs.forEach(log => {
const row = document.createElement('tr');
        row.className = 'hover:bg-gray-50';
        row.innerHTML = `
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.id}</td>
            <td class="px-6 py-4 whitespace-nowrap">
                <span class="status-badge ${getStatusClass(log.status)}">${log.status}</span>
            </td>
            <td class="px-6 py-4 whitespace-nowrap">
                <span class="status-badge ${getMethodClass(log.method)}">${log.method}</span>
            </td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.time}</td>
            <td class="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">${log.url}</td>
            <td class="px-6 py-4 text-sm text-gray-500 truncate max-w-xs">${log.errorMessage}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                <button class="view-btn p-1 rounded hover:bg-gray-200" data-id="${log.id}">
                    <i data-feather="eye" class="w-4 h-4 text-primary-500"></i>
                </button>
            </td>
        `;
        logsTable.appendChild(row);
    });
    
    // Add event listeners to view buttons
    document.querySelectorAll('.view-btn').forEach(btn => {
        btn.addEventListener('click', (e) => {
            const id = parseInt(e.currentTarget.getAttribute('data-id'));
            currentLog = sampleLogs.find(log => log.id === id);
            showErrorDetails(currentLog);
        });
    });
    
    feather.replace();
}

// Helper function to get status badge class
function getStatusClass(status) {
    if (status >= 200 && status < 300) return 'status-2xx';
    if (status >= 400 && status < 500) return 'status-4xx';
    if (status >= 500) return 'status-5xx';
    return '';
}

// Helper function to get method badge class
function getMethodClass(method) {
    return `method-${method.toLowerCase()}`;
}
// Function to show error details in modal
function showErrorDetails(log) {
    // Request Info
    document.getElementById('modalStatus').textContent = log.status;
    document.getElementById('modalStatus').className = `status-badge ${getStatusClass(log.status)}`;
    document.getElementById('modalMethod').textContent = log.method;
    document.getElementById('modalMethod').className = `status-badge ${getMethodClass(log.method)}`;
    document.getElementById('modalEndpoint').textContent = log.url;
    document.getElementById('modalTime').textContent = log.time;
// Error Info
    document.getElementById('modalErrorCode').textContent = log.errorCode;
    document.getElementById('modalErrorType').textContent = log.errorType;
    document.getElementById('modalErrorType').className = 'status-badge status-4xx';
    
    // Mock additional data
    document.getElementById('modalDuration').textContent = `${Math.floor(Math.random() * 500) + 100}ms`;
    document.getElementById('modalOccurrences').textContent = Math.floor(Math.random() * 10) + 1;
    
    const firstDate = new Date(log.time);
    const lastDate = new Date(log.time);
    firstDate.setDate(firstDate.getDate() - Math.floor(Math.random() * 3));
    
    document.getElementById('modalFirstOccurred').textContent = firstDate.toLocaleString();
    document.getElementById('modalLastOccurred').textContent = lastDate.toLocaleString();
    
    document.getElementById('modalErrorMessage').textContent = log.errorMessage;
    document.getElementById('modalResolution').textContent = log.resolution;
    errorModal.classList.remove('hidden');
    document.body.style.overflow = 'hidden';
    errorModal.style.display = 'flex';
}

// Function to close modal
function closeErrorModal() {
    errorModal.classList.add('hidden');
    errorModal.style.display = 'none';
    document.body.style.overflow = 'auto';
    currentLog = null;
}
// Event listeners
closeModal.addEventListener('click', closeErrorModal);
closeModalBtn.addEventListener('click', closeErrorModal);
submitTicket.addEventListener('click', () => {
    alert(`Ticket submitted for error: ${currentLog.errorCode}\nAn engineer will review this issue shortly.`);
    closeErrorModal();
});
// Initialize the page
document.addEventListener('DOMContentLoaded', () => {
    renderLogsTable();
    
    // Close modal when clicking outside
    errorModal.addEventListener('click', (e) => {
        if (e.target === errorModal) {
            closeErrorModal();
        }
    });

    // Search functionality
    searchInput.addEventListener('input', (e) => {
        renderLogsTable(e.target.value);
    });
});