From 86c6cd3cc099d2480932ede03c12cea01e625c94 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 26 Apr 2026 21:56:28 +0000
Subject: [PATCH] =Requiring files based on Site class settings
---
inc/rest/routes/ErrorRoutes.php | 64 ++++++++++++++++++--------------
1 files changed, 36 insertions(+), 28 deletions(-)
diff --git a/inc/rest/routes/ErrorRoutes.php b/inc/rest/routes/ErrorRoutes.php
index d76c79c..aab3658 100644
--- a/inc/rest/routes/ErrorRoutes.php
+++ b/inc/rest/routes/ErrorRoutes.php
@@ -1,15 +1,16 @@
<?php
namespace JVBase\rest\routes;
-use JVBase\JVB;
-use JVBase\rest\RestRouteManager;
+use JVBase\rest\Response;
+use JVBase\rest\Rest;
+use JVBase\rest\Route;
use WP_REST_Request;
use WP_REST_Response;
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
-class ErrorRoutes extends RestRouteManager
+class ErrorRoutes extends Rest
{
/**
* Registers error routes
@@ -17,13 +18,16 @@
*/
public function registerRoutes():void
{
- register_rest_route($this->namespace, '/errors/log', [
- [
- 'methods' => 'POST',
- 'callback' => [$this, 'handleErrorLog'],
- 'permission_callback' => '__return_true', // Allow anyone to log errors
- ]
- ]);
+ Route::for('errors/log')
+ ->post([$this, 'handleErrorLog'])
+ ->args([
+ 'error_type' => 'string|required|enum:network,timeout,offline,auth,rate_limit,server,client,unknown',
+ 'message' => 'string|required',
+ 'context' => 'string',
+ ])
+ ->auth('public')
+ ->rateLimit(10)
+ ->register();
}
/**
@@ -31,27 +35,31 @@
*
* @return WP_REST_Response
*/
- public function handleErrorLog(WP_REST_Request$request):WP_REST_Response
- {
- $error_type = $request->get_param('error_type');
- $message = $request->get_param('message');
- $context = json_decode($request->get_param('context'), true);
+ public function handleErrorLog(WP_REST_Request $request): WP_REST_Response
+ {
+ $error_type = sanitize_text_field($request->get_param('error_type'));
+ $message = sanitize_text_field($request->get_param('message'));
+ $context = $request->get_param('context');
- // Determine severity based on error type
- $severity = $this->getSeverityFromType($error_type);
+ // Parse context JSON if provided
+ $contextData = [];
+ if (!empty($context)) {
+ $decoded = json_decode($context, true);
+ $contextData = is_array($decoded) ? $decoded : [];
+ }
- JVB()->error()->log(
- $context['component'] ?? 'client-js',
- $message,
- $context,
- $severity
- );
+ // Determine severity based on error type
+ $severity = $this->getSeverityFromType($error_type);
- return new WP_REST_Response([
- 'success' => true,
- 'message' => 'Error logged'
- ]);
- }
+ JVB()->error()->log(
+ $contextData['component'] ?? 'client-js',
+ $message,
+ $contextData,
+ $severity
+ );
+
+ return Response::success(['message'=>'Error logged']);
+ }
/**
* @param string $type
--
Gitblit v1.10.0