- Create PSA_Cost_Tracker class with database table for API call logging - Log prompt/completion tokens and estimated cost for every OpenRouter API call - Implement monthly budget system with hard stop (budget of 0 = unlimited) - Add budget checks in validate_peptide_name() and generate_peptide_content() - Add dry_run() method to estimate costs before making API calls - Display monthly usage summary and recent API logs in admin settings - Add monthly_budget setting to admin interface with number input field - Update uninstall.php to drop psa_api_logs table on plugin removal Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
975 B
PHP
Executable File
40 lines
975 B
PHP
Executable File
<?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
|
|
);
|
|
}
|
|
}
|