ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
feat(errors): report client errors and add error-logs API methods
Juan Denis6aaf8d9dd9c7
diff --git a/frontend/src/components/ErrorBoundary.jsx b/frontend/src/components/ErrorBoundary.jsxindex 029c0d20..f09379fb 100644--- a/frontend/src/components/ErrorBoundary.jsx+++ b/frontend/src/components/ErrorBoundary.jsx@@ -1,5 +1,6 @@import { Component } from 'react';import { AlertTriangle, RefreshCw } from 'lucide-react';+import api from '../services/api';// Class-based Error Boundary for catching React errorsexport class ErrorBoundary extends Component {@@ -15,6 +16,21 @@ export class ErrorBoundary extends Component {componentDidCatch(error, errorInfo) {this.setState({ errorInfo });console.error('ErrorBoundary caught an error:', error, errorInfo);+ // Fire-and-forget report to the backend error tracker. Wrapped so+ // reporting can NEVER throw inside the boundary — reportClientError+ // already swallows network failures; this guards payload assembly.+ try {+ api.reportClientError({+ message: error?.message || 'Unknown error',+ exception_type: error?.name,+ traceback: error?.stack,+ endpoint: window.location.pathname,+ context: {+ componentStack: errorInfo?.componentStack?.slice(0, 2000),+ userAgent: navigator.userAgent,+ },+ });+ } catch { /* reporting must never break the boundary */ }}handleRetry = () => {diff --git a/frontend/src/services/api/errorLogs.js b/frontend/src/services/api/errorLogs.jsnew file mode 100644index 00000000..680a5fb6--- /dev/null+++ b/frontend/src/services/api/errorLogs.js@@ -0,0 +1,55 @@+// Error tracking API methods. Mixed into ApiService (see ./index.js) so each+// function runs with `this` bound to the client and calls `this.request(...)`.++// --- Admin error log (JWT) ---++export async function getErrorLogs(params = {}) {+ const query = new URLSearchParams();+ if (params.source) query.append('source', params.source);+ if (params.resolved !== undefined && params.resolved !== null && params.resolved !== '') {+ query.append('resolved', params.resolved);+ }+ if (params.search) query.append('search', params.search);+ if (params.page) query.append('page', params.page);+ if (params.per_page) query.append('per_page', params.per_page);+ const suffix = query.toString() ? `?${query}` : '';+ return this.request(`/error-logs${suffix}`);+}++export async function getErrorLogStats() {+ return this.request('/error-logs/stats');+}++export async function getErrorLog(id) {+ return this.request(`/error-logs/${id}`);+}++export async function resolveErrorLog(id, resolved) {+ return this.request(`/error-logs/${id}/resolve`, {+ method: 'POST',+ body: JSON.stringify({ resolved }),+ });+}++export async function deleteErrorLog(id) {+ return this.request(`/error-logs/${id}`, { method: 'DELETE' });+}++// --- Client-side error ingestion (public-ish) ---+//+// Deliberately NOT this.request(): the report has to go out even when the+// caller's token is expired or missing (an expired session is exactly when a+// boundary error is likely), and a failed error report must never throw —+// it is called from ErrorBoundary.componentDidCatch, where throwing would+// re-trip the boundary it is reporting from.+export async function reportClientError(payload) {+ try {+ await fetch(`${this.baseUrl}/error-logs/client`, {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify(payload),+ });+ } catch {+ // Swallow: reporting is best-effort.+ }+}diff --git a/frontend/src/services/api/index.js b/frontend/src/services/api/index.jsindex 4e6cdaa5..dd639c23 100644--- a/frontend/src/services/api/index.js+++ b/frontend/src/services/api/index.js@@ -49,6 +49,7 @@ import * as dashboardMethods from './dashboards.js';import * as monitorMethods from './monitors.js';import * as viewMethods from './views.js';import * as recycleBinMethods from './recycleBin.js';+import * as errorLogMethods from './errorLogs.js';class ApiService extends ApiClient {constructor() {@@ -105,6 +106,7 @@ class ApiService extends ApiClient {monitorMethods,viewMethods,recycleBinMethods,+ errorLogMethods,];for (const mod of modules) {for (const [key, fn] of Object.entries(mod)) {