File size: 16,955 Bytes
683a499
 
64c9a90
683a499
 
 
7b8315a
1bc6b84
683a499
 
 
1bc6b84
683a499
 
 
 
 
1bc6b84
 
 
683a499
 
1bc6b84
683a499
 
 
 
1bc6b84
 
 
 
683a499
 
1bc6b84
cb9e543
 
 
 
 
1bc6b84
 
 
 
 
 
cb9e543
 
1bc6b84
cb9e543
 
1bc6b84
 
 
 
 
 
683a499
 
 
 
01e8cf0
b21db35
 
 
 
683a499
 
01e8cf0
db778e6
683a499
 
db778e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e8c5134
db778e6
 
 
0244a08
 
 
 
 
 
 
 
 
 
01e8cf0
683a499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6210a2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b21db35
 
0a37eee
 
 
 
6210a2f
b21db35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a37eee
b21db35
683a499
 
b21db35
 
 
 
 
 
 
 
 
 
 
 
 
6210a2f
 
 
 
 
 
 
 
 
683a499
 
 
91081ff
b1c16da
 
6210a2f
 
683a499
 
91081ff
 
 
 
 
 
 
 
 
 
 
 
 
6210a2f
683a499
 
6210a2f
 
 
 
 
 
eb1f09d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6210a2f
 
 
 
eb1f09d
683a499
28fa7d6
683a499
 
 
6210a2f
 
 
 
 
 
683a499
 
 
 
6210a2f
 
 
 
 
 
bed69da
1bc6b84
683a499
 
 
 
0740dae
0a37eee
 
 
 
 
 
 
 
 
 
 
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
// Sample data - in a real app this would come from an API
const sampleLogs = [
    {
        id: 1,
        status: 500,
        method: 'POST',
        time: '2025-10-18 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 searchInput = document.querySelector('input[type="text"]');
let errorModal;
let closeModal;
let closeModalBtn;
let submitTicket;
// Current selected log
let currentLog = null;
// Function to render logs table with optional filter
function renderLogsTableWithFilter(filteredLogs) {
    logsTable.innerHTML = '';
    
    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 new 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();
}

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()}`;
}
// Sample error details data
const errorDetails = {
    1: {
        requestHeaders: {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
            'X-Request-ID': 'req_123456'
        },
        requestBody: {
            "username": "testuser",
            "email": "test@example.com"
        },
        stackTrace: "Error: Database connection timeout\n    at Query._callback (/app/src/db.js:45:15)\n    at Query.Sequence.end (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)"
    },
    2: {
        requestHeaders: {
            'Accept': 'application/json',
            'X-API-Version': '1.0'
        },
        requestBody: null,
        stackTrace: "Error: Product not found\n    at ProductService.find (/app/src/services/product.js:32:11)\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
    },
    3: {
        requestHeaders: {
            'Content-Type': 'application/json',
            'X-Client-ID': 'web_app_v2'
        },
        requestBody: {
            "order_id": 678,
            "status": "processing"
        },
        stackTrace: "ValidationError: Missing required field 'quantity'\n    at validateOrderUpdate (/app/src/validators/order.js:15:15)"
    }
};
// Function to create modal elements
function createModalElements() {
    const modal = document.getElementById('errorModal');
    if (modal.innerHTML) return modal; // Already created
    
modal.innerHTML = `
<div class="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto">
            <div class="p-6">
                <div class="flex justify-between items-center mb-4">
                    <h2 class="text-xl font-bold text-gray-800">Error Details</h2>
                    <button id="closeModal" class="text-gray-500 hover:text-gray-700 p-2">
                        <i data-feather="x" class="w-5 h-5"></i>
                    </button>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                    <div>
                        <h3 class="font-medium text-gray-700 mb-2">Request Information</h3>
                        <div class="space-y-2">
                            <p><span class="font-medium">Status:</span> <span id="modalStatus" class="px-2 py-1 rounded text-xs"></span></p>
                            <p><span class="font-medium">Method:</span> <span id="modalMethod" class="px-2 py-1 rounded text-xs"></span></p>
                            <p><span class="font-medium">Endpoint:</span> <span id="modalEndpoint" class="break-all"></span></p>
                            <p><span class="font-medium">Timestamp:</span> <span id="modalTime" class="font-mono"></span></p>
                            <p><span class="font-medium">Request Duration:</span> <span id="modalDuration" class="font-mono">-</span></p>
                        </div>
                    </div>
                    <div>
                        <h3 class="font-medium text-gray-700 mb-2">Error Information</h3>
                        <div class="space-y-2">
                            <p><span class="font-medium">Error Code:</span> <span id="modalErrorCode" class="font-mono"></span></p>
                            <p><span class="font-medium">Error Type:</span> <span id="modalErrorType" class="px-2 py-1 rounded text-xs"></span></p>
                            <p><span class="font-medium">Occurrences:</span> <span id="modalOccurrences" class="font-mono">1</span></p>
                            <p><span class="font-medium">First Occurred:</span> <span id="modalFirstOccurred" class="font-mono">-</span></p>
                            <p><span class="font-medium">Last Occurred:</span> <span id="modalLastOccurred" class="font-mono">-</span></p>
                        </div>
                    </div>
                </div>
                <div class="mb-6">
                    <h3 class="font-medium text-gray-700 mb-2">Full Error Message</h3>
                    <div class="bg-gray-50 p-4 rounded">
                        <pre id="modalErrorMessage" class="text-sm whitespace-pre-wrap overflow-x-auto font-mono"></pre>
                    </div>
                </div>
                <div class="mb-6 hidden" id="requestDetails">
                    <h3 class="font-medium text-gray-700 mb-2">Request Details</h3>
                    <div class="bg-gray-50 p-4 rounded">
                        <pre id="modalRequestDetails" class="text-sm whitespace-pre-wrap overflow-x-auto font-mono"></pre>
                    </div>
                </div>
                <div class="mb-6">
                    <h3 class="font-medium text-gray-700 mb-2">Resolution Steps</h3>
                    <div id="modalResolution" class="bg-blue-50 p-4 rounded text-sm"></div>
                </div>
                <div class="flex justify-end space-x-3">
                    <button id="submitTicket" class="px-4 py-2 bg-secondary-500 text-white rounded-md hover:bg-secondary-600 transition flex items-center">
                        <i data-feather="plus" class="mr-2 w-4 h-4"></i> Submit Ticket
                    </button>
                    <button id="closeModalBtn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 transition">
                        Close
                    </button>
                </div>
            </div>
        </div>
    `;
return modal;
}
// Function to show error details in modal
function showErrorDetails(log) {
    if (!errorModal) {
        errorModal = createModalElements();
        closeModal = document.getElementById('closeModal');
        closeModalBtn = document.getElementById('closeModalBtn');
        submitTicket = document.getElementById('submitTicket');
        
        // Setup event listeners for modal
        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();
        });
        
        // Close when clicking outside modal
        errorModal.addEventListener('click', (e) => {
            if (e.target === errorModal) {
                closeErrorModal();
            }
        });
    }
    // 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();
    
    // Error details
    document.getElementById('modalErrorMessage').textContent = log.errorMessage;
    document.getElementById('modalResolution').textContent = log.resolution;
    
    // Show request details if available
    const requestDetailsSection = document.getElementById('requestDetails');
    const requestDetailsContent = document.getElementById('modalRequestDetails');
    if (errorDetails[log.id]) {
        const details = errorDetails[log.id];
        
        // Format the request details more cleanly
        let detailsStr = '=== Request Headers ===\n';
        detailsStr += JSON.stringify(details.requestHeaders, null, 2) + '\n\n';
        
        if (details.requestBody) {
            detailsStr += '=== Request Body ===\n';
            detailsStr += JSON.stringify(details.requestBody, null, 2) + '\n\n';
        }
        
        if (details.stackTrace) {
            detailsStr += '=== Stack Trace ===\n';
            detailsStr += details.stackTrace + '\n';
        }
        
        requestDetailsContent.textContent = detailsStr;
        requestDetailsSection.classList.remove('hidden');
    } else {
        requestDetailsSection.classList.add('hidden');
    }
errorModal.classList.remove('hidden');
    document.body.style.overflow = 'hidden';
    errorModal.style.display = 'flex';
}
// Function to close modal
function closeErrorModal() {
    if (errorModal) {
        errorModal.classList.add('hidden');
        errorModal.style.display = 'none';
        document.body.style.overflow = 'auto';
        currentLog = null;
    }
}
// Initialize the page
document.addEventListener('DOMContentLoaded', () => {
    renderLogsTable();
    // Search functionality
    searchInput.addEventListener('input', (e) => {
        renderLogsTable(e.target.value);
    });
    // Initialize modal (but don't show it yet)
    errorModal = createModalElements();
// Setup event listeners for modal
    errorModal.addEventListener('click', (e) => {
        if (e.target === errorModal) {
            closeErrorModal();
        }
    });
});
// Global event delegation for modal buttons
document.addEventListener('click', (e) => {
    if (e.target.closest('#closeModal, #closeModalBtn')) {
        closeErrorModal();
    } else if (e.target.closest('#submitTicket')) {
        if (currentLog) {
            alert(`Ticket submitted for error: ${currentLog.errorCode}\nAn engineer will review this issue shortly.`);
            closeErrorModal();
        }
    }
});