diff --git a/includes/Api/ProductsController.php b/includes/Api/ProductsController.php index 74a530d..dbf7a20 100644 --- a/includes/Api/ProductsController.php +++ b/includes/Api/ProductsController.php @@ -92,8 +92,10 @@ class ProductsController { * Get products list with filters */ public static function get_products(WP_REST_Request $request) { - error_log('WooNooW ProductsController::get_products() CALLED'); - $page = max(1, (int) $request->get_param('page')); + 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'); $status = $request->get_param('status'); @@ -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]); + } } /**