Download script.js from Sanoopsn/failtrack-api-error-logger: direct link, hf CLI and curl.
- Browser
- Download file 7.85 kB
-
https://huggingface.co/spaces/Sanoopsn/failtrack-api-error-logger/resolve/28fa7d6d568fe2b19f86a90e3fe3fb29bbcb3be5/script.js
- Command line
-
hf download hf://spaces/Sanoopsn/failtrack-api-error-logger@28fa7d6d568fe2b19f86a90e3fe3fb29bbcb3be5/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Sanoopsn/failtrack-api-error-logger/resolve/28fa7d6d568fe2b19f86a90e3fe3fb29bbcb3be5/script.js
7.85 kB
| // 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); | |
| }); | |
| }); | |