SEC-001 CRITICAL: Remove spoofable X-Forwarded-For/X-Real-IP from IP detection; trust only CF-Connecting-IP + REMOTE_ADDR SEC-004 HIGH: Add peptide name input validation with character whitelist and prompt injection blocking SEC-006 HIGH: Add missing return after wp_send_json_success in handle_pending_retry max-retries block SEC-007 MEDIUM: KB articles now respect auto_publish setting instead of always publishing SEC-009 MEDIUM: Replace hardcoded page ID 73 with configurable kb_page_id setting SEC-010 MEDIUM: Fix cache invalidation — add underscore prefix to transient name pattern SEC-011 MEDIUM: Skip sleep() during WP-Cron to avoid blocking PHP workers on rate limit retry SEC-012 MEDIUM: Add global daily generation cap (50/day) to prevent cost overruns SEC-013 LOW: Add @deprecated notice to unused PSA_Error class SEC-015 LOW: Convert uninstall.php from space to tab indentation (WPCS) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
975 B
PHP
40 lines
975 B
PHP
<?php
|
|
/**
|
|
* Standardized error handling for Peptide Search AI.
|
|
* Provides a unified interface for sending error responses with consistent structure.
|
|
*
|
|
* @package PeptideSearchAI
|
|
* @deprecated 4.1.0 Currently unused. Retained for potential future integration.
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
class PSA_Error {
|
|
|
|
// Error type constants
|
|
const TYPE_VALIDATION = 'validation_error';
|
|
const TYPE_RATE_LIMIT = 'rate_limit_error';
|
|
const TYPE_SYSTEM = 'system_error';
|
|
const TYPE_NOT_FOUND = 'not_found';
|
|
|
|
/**
|
|
* Send a standardized error response.
|
|
*
|
|
* @param string $type The error type (one of the TYPE_* constants).
|
|
* @param string $message User-friendly error message.
|
|
* @param int $http_code HTTP response code (default 400).
|
|
* @return void
|
|
*/
|
|
public static function send( $type, $message, $http_code = 400 ) {
|
|
wp_send_json_error(
|
|
array(
|
|
'error_type' => $type,
|
|
'message' => $message,
|
|
),
|
|
$http_code
|
|
);
|
|
}
|
|
}
|