aboutsummaryrefslogtreecommitdiff
path: root/api/debug/errors.php
blob: 1ed9a2fe1493ce18bf41cf20be4b7bf84cf824ad (plain)
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
<?php
require_once __DIR__ . '/config.php';

$errors = load_json(ERRORS_FILE);

// Filters
$type = $_GET['type'] ?? null;
$severity = $_GET['severity'] ?? null;
$module = $_GET['module'] ?? null;
$category = $_GET['category'] ?? null;
$search = $_GET['search'] ?? null;
$from = $_GET['from'] ?? null;
$to = $_GET['to'] ?? null;
$session = $_GET['session'] ?? null;
$page = max(1, (int)($_GET['page'] ?? 1));
$perPage = min(100, max(1, (int)($_GET['per_page'] ?? 50)));

$filtered = array_filter($errors, function($e) use ($type, $severity, $module, $category, $search, $from, $to, $session) {
    if ($type && ($e['type'] ?? '') !== $type) return false;
    if ($severity && ($e['severity'] ?? '') !== $severity) return false;
    if ($module && ($e['module'] ?? '') !== $module) return false;
    if ($category && ($e['category'] ?? '') !== $category) return false;
    if ($session && ($e['session_id'] ?? '') !== $session) return false;
    if ($search && stripos($e['message'] ?? '', $search) === false) return false;
    if ($from && ($e['ingested_at'] ?? '') < $from) return false;
    if ($to && ($e['ingested_at'] ?? '') > $to) return false;
    return true;
});

$filtered = array_values($filtered);
$total = count($filtered);
$totalPages = max(1, ceil($total / $perPage));
$offset = ($page - 1) * $perPage;
$pageErrors = array_slice($filtered, $offset, $perPage);

json_response([
    'success' => true,
    'total' => $total,
    'page' => $page,
    'per_page' => $perPage,
    'total_pages' => $totalPages,
    'errors' => $pageErrors,
]);