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; } }