PHP Classes

File: application/modules/extensions/aws/Aws/S3/RetryableMalformedResponseParser.php

Recommend this page to a friend!
  Classes of Tran Tuan   Pretty PHP S3 Files Manager   application/modules/extensions/aws/Aws/S3/RetryableMalformedResponseParser.php   Download  
File: application/modules/extensions/aws/Aws/S3/RetryableMalformedResponseParser.php
Role: Application script
Content type: text/plain
Description: Application script
Class: Pretty PHP S3 Files Manager
Web based interface to manage files in Amazon S3
Author: By
Last change:
Date: 8 years ago
Size: 1,210 bytes
 

Contents

Class file image Download
<?php
namespace Aws\S3;

use
Aws\Api\Parser\AbstractParser;
use
Aws\Api\Parser\Exception\ParserException;
use
Aws\CommandInterface;
use
Aws\Exception\AwsException;
use
Psr\Http\Message\ResponseInterface;

/**
 * Converts malformed responses to a retryable error type.
 *
 * @internal
 */
class RetryableMalformedResponseParser extends AbstractParser
{
   
/** @var callable */
   
private $parser;
   
/** @var string */
   
private $exceptionClass;

    public function
__construct(
        callable
$parser,
       
$exceptionClass = AwsException::class
    ) {
       
$this->parser = $parser;
       
$this->exceptionClass = $exceptionClass;
    }

    public function
__invoke(
       
CommandInterface $command,
       
ResponseInterface $response
   
) {
       
$fn = $this->parser;

        try {
            return
$fn($command, $response);
        } catch (
ParserException $e) {
            throw new
$this->exceptionClass(
               
"Error parsing response for {$command->getName()}:"
                   
. " AWS parsing error: {$e->getMessage()}",
               
$command,
                [
'connection_error' => true, 'exception' => $e],
               
$e
           
);
        }
    }
}