debug: Add try-catch to get_products to catch silent errors
Wrapped entire get_products() in try-catch. Will log: - START when function begins - END SUCCESS when completes - ERROR + stack trace if exception thrown This will reveal if there's a PHP error causing silent failure.
This commit is contained in:
@@ -92,7 +92,9 @@ class ProductsController {
|
||||
* Get products list with filters
|
||||
*/
|
||||
public static function get_products(WP_REST_Request $request) {
|
||||
error_log('WooNooW ProductsController::get_products() CALLED');
|
||||
error_log('WooNooW ProductsController::get_products() CALLED - START');
|
||||
|
||||
try {
|
||||
$page = max(1, (int) $request->get_param('page'));
|
||||
$per_page = min(100, max(1, (int) ($request->get_param('per_page') ?: 20)));
|
||||
$search = $request->get_param('search');
|
||||
@@ -184,7 +186,14 @@ class ProductsController {
|
||||
$response->header('Expires', '0');
|
||||
$response->header('X-WooNooW-Version', '2.0'); // Debug header
|
||||
|
||||
error_log('WooNooW ProductsController::get_products() CALLED - END SUCCESS');
|
||||
return $response;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
error_log('WooNooW ProductsController::get_products() ERROR: ' . $e->getMessage());
|
||||
error_log('WooNooW ProductsController::get_products() TRACE: ' . $e->getTraceAsString());
|
||||
return new WP_Error('products_error', $e->getMessage(), ['status' => 500]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user