Uname: Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
Software: LiteSpeed
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.213.251.212
Your Ip: 18.222.50.201
User: allssztx (535) | Group: allssztx (533)
Safe Mode: OFF
Disable Function:
NONE

name : client-response.php
<?php

namespace ImageOptimization\Classes\Client;

use Exception;
use ImageOptimization\Classes\Exceptions\Quota_Exceeded_Error;
use ImageOptimization\Modules\Optimization\Classes\Exceptions\Bulk_Token_Expired_Error;
use ImageOptimization\Modules\Optimization\Classes\Exceptions\Image_Already_Optimized_Error;
use Throwable;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

class Client_Response {
	private array $known_errors;
	/**
	 * @var mixed
	 */
	private $response;

	/**
	 * @throws Throwable|Quota_Exceeded_Error|Bulk_Token_Expired_Error|Image_Already_Optimized_Error
	 */
	public function handle() {
		if ( ! is_wp_error( $this->response ) ) {
			return $this->response;
		}

		$message = $this->response->get_error_message();

		if ( isset( $this->known_errors[ $message ] ) ) {
			throw $this->known_errors[ $message ];
		}

		throw new Exception( $message );
	}

	public function __construct( $response ) {
		$this->known_errors = [
			'user reached limit' => new Quota_Exceeded_Error( esc_html__( 'Plan quota reached', 'image-optimization' ) ),
			'Bulk token expired' => new Bulk_Token_Expired_Error( esc_html__( 'Bulk token expired', 'image-optimization' ) ),
			'Image already optimized' => new Image_Already_Optimized_Error( esc_html__( 'Image already optimized', 'image-optimization' ) ),
		];
		$this->response = $response;
	}
}
© 2025 GrazzMean-Shell