Wrap guzzle errors into

@param RequestInterface $request
@param array            $skipCodes Method should return null if code matched.
@return ResponseInterface
6570
private function run(RequestInterface $request, array $skipCodes = []): ?ResponseInterface
    {
        try {
            return $this->client->send($request);
        } catch (GuzzleException $e) {
            if (in_array($e->getCode(), $skipCodes)) {
                return null;
            }

            throw new ServerException($e->getMessage(), $e->getCode(), $e);
        }
    }
1313324
public function serialize($skipObjects = false)
    {
        $this->_prepareData();
        $temporaryData  = $this->toArray();
        $data           = '';

        if ($skipObjects) {
            $temporaryData = $this->traveler(
                'self::_skipObject',
                null,
                $temporaryData,
                true
            );
        }

        try {
            $data = Serializer::serialize($temporaryData);
        } catch (ExceptionInterface $exception) {
            $this->_addException($exception);
        }

        return $data;
    }
163262
public function respondValidationError(
        $code = ApiResponse::CODE_VALIDATION_ERROR,
        array $errors = [],
        $message = null
    ): JsonResponse {
        return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY)
            ->respond([
                'status' => [
                    'type' => 'error',
                    'message' => $this->getDefaultMessage($code, $message),
                    'code' => $code,
                    'http_code' => $this->getStatusCode(),
                ],
                'errors' => $errors,
            ]);
    }
275766
private function makeNotFoundResponse(Request $request): Promise {
        return $this->errorHandler->handleError(Status::NOT_FOUND, null, $request);
    }
561290
public function getExceptionFor(RequestInterface $request): ClientExceptionInterface
    {
        try {
            return $this->exceptions[$request];
        } catch (\UnexpectedValueException $e) {
            throw new \UnexpectedValueException('Request not found', $e->getCode(), $e);
        }
    }
291419
private function processRequest($request)
    {
        if (!is_array($request)) {
            return self::requestError();
        }

        // The presence of the 'id' key indicates that a response is expected
        $isQuery = array_key_exists('id', $request);

        $id = &$request['id'];

        if (($id !== null) && !is_int($id) && !is_float($id) && !is_string($id)) {
            return self::requestError();
        }

        $version = &$request['jsonrpc'];

        if ($version !== self::VERSION) {
            return self::requestError($id);
        }

        $method = &$request['method'];

        if (!is_string($method)) {
            return self::requestError($id);
        }

        // The 'params' key is optional, but must be non-null when provided
        if (array_key_exists('params', $request)) {
            $arguments = $request['params'];

            if (!is_array($arguments)) {
                return self::requestError($id);
            }
        } else {
            $arguments = array();
        }

        if ($isQuery) {
            return $this->processQuery($id, $method, $arguments);
        }

        $this->processNotification($method, $arguments);
        return null;
    }
684744
public function toResponse($request)
    {
        if(! $this->handler && ! is_callable($this->handler)) {
            throw new ErrorException("No handler set");
        }

        $parameters = array_merge(
            [$request, $this->action],
            $this->parameters
        );

        try {
            $payload = call_user_func_array($this->handler, array_values($parameters));
        }
        catch (Exception $e) {
            // We'll assume that if an Exception has an error code 
            // that is explicitly defined, we want to use it as an
            // HTTP error code. if not we'll just let the 
            // Exception handler takes care of it. 
            $code = $e->getCode();

            if (! $this->isValidHttpStatusCode($code)) {
                throw $e;
            }
            
            $this->setStatusCode($code);

            return $e instanceof HasMessageBag 
                ? $this->respondWithMessageBag($e->getMessageBag(), class_basename($e))
                : $this->respondWithError($e->getMessage(), class_basename($e));
        }   
        catch (ValidationException $e) {
            throw $e;
        }

        return $this->handlePayload($payload);
    }
949682
protected function send(RequestInterface $request)
    {
        try {
            $response = $this->httpClient->sendRequest($request);

            $body = (string) $response->getBody();

            return \json_decode($body, true);
        } catch (\Exception $e) {
            throw new ErrorException(sprintf('There was an error requesting Paylands API: %s', $e->getMessage()));
        }
    }
1156530
public function onBeforeHTTPError($code, $request)
    {

        $errorPage = ErrorPage::get()->filter(array(
                'ErrorCode' => $code,
                'SiteID' => Multisites::inst()->getCurrentSiteId()
            ))->first();
        if ($errorPage) {
            Requirements::clear();
            Requirements::clear_combined_files();
            $response = ModelAsController::controller_for($errorPage)->handleRequest($request);
            throw new HTTPResponse_Exception($response, $code);
        }
    }
478307
private function onRejected(RequestInterface $request, array $options)
    {
        return function ($reason) use ($request, $options) {
            if (!$reason instanceof ClientException) {
                return new RejectedPromise($reason);
            }

            $response = $reason->getResponse();

            if ($next = $this->handleUnauthenticatedResponse($request, $response, $options)) {
                return $next;
            }

            return new RejectedPromise($reason);
        };
    }
593172
private function collectRequest(GuzzleRequestInterface $request)
    {
        $body = null;
        if ($request instanceof EntityEnclosingRequestInterface) {
            $body = (string) $request->getBody();
        }

        return array(
            'headers' => $request->getHeaders(),
            'method'  => $request->getMethod(),
            'scheme'  => $request->getScheme(),
            'host'    => $request->getHost(),
	    'port'    => $request->getPort(),
            'path'    => $request->getPath(),
            'query'   => $request->getQuery(),
            'body'    => $body
        );
    }
448740
protected function respondWithError(
        $message = 'Bad Request',
        $code = SymfonyResponse::HTTP_BAD_REQUEST,
        array $headers = []
    ) {
        return abort($code, $message, $headers);
    }
287806
private function GetMessage($code)
	{
		$errors = array();
		$errors["-1"] = "Error in request Data was not by received intact by Skipjack Transaction Network.";
		$errors["0"] = "Communication Failure Error in Request and Response at IP level. Use Get Transaction Status before retrying transaction.";
		$errors["1"] = "Success";
		$errors["-35"] = "Credit card number does not comply with the Mod10 check. Retry with correct credit card number.";
		$errors["-37"] = "Skipjack is unable to communicate with payment Processor.  Please Retry.";
		$errors["-39"] = "Check HTML Serial Number length and that it is a correct/valid number. Confirm you are sending to the correct environment (Development or Production)";
		$errors["-51"] = "Length or value of zip code The value or length for billing zip code is incorrect.";
		$errors["-52"] = "The value or length for shipping zip code is incorrect.";
		$errors["-53"] = "The value or length for credit card expiration month is incorrect.";
		$errors["-54"] = "The value or length of the month or year of the credit card account number was incorrect.";
		$errors["-55"] = "The value or length or billing street address is incorrect.";
		$errors["-56"] = "The value or length of the shipping address is incorrect.";
		$errors["-57"] = "The length of the transaction amount must be at least 3 digits long (excluding the decimal place).";
		$errors["-58"] = "Merchant Name associated with Skipjack account is misconfigured or invalid";
		$errors["-59"] = "Merchant Address associated with Skipjack account is misconfigured or invalid Skipjack Financial Services Skipjack Integration GuidePage 52 of 251";
		$errors["-60"] = "Merchant State associated with Skipjack account is misconfigured or invalid";
		$errors["-61"] = "The value or length for shipping state/province is empty.";
		$errors["-62"] = "The value for length orderstring is empty.";
		$errors["-64"] = "The value for the phone number is incorrect.";
		$errors["-65"] = "Error empty sjname The value or length for billing name is empty.";
		$errors["-66"] = "The value or length for billing e-mail is empty.";
		$errors["-67"] = "The value or length for billing street address is empty.";
		$errors["-68"] = "The value or length for billing city is empty.";
		$errors["-69"] = "The value or length for billing state is empty.";
		$errors["-70"] = "Zip Code field is empty.";
		$errors["-71"] = "Ordernumber field is empty.";
		$errors["-72"] = "Account number field is empty";
		$errors["-73"] = "Month field is empty.";
		$errors["-74"] = "Year field is empty.";
		$errors["-75"] = "Serial number field is empty.";
		$errors["-76"] = "Transaction amount field is empty.";
		$errors["-77"] = "Orderstring field is empty.";
		$errors["-78"] = "Shiptophone field is empty.";
		$errors["-79"] = "Length or value sjname The value or length for billing name is empty.";
		$errors["-80"] = "Error in the length or value of shiptophone.";
		$errors["-81"] = "Length or value of Customer location";
		$errors["-82"] = "The value or length for billing state is empty.";
		$errors["-83"] = "The value or length for shipping phone is empty.";
		$errors["-84"] = "There is already an existing pending transaction in the register sharing the posted Order Number.";
		$errors["-85"] = "Airline leg field value is invalid or empty.";
		$errors["-86"] = "Airline ticket info field is invalid or empty";
		$errors["-87"] = "Point of Sale check routing number is invalid or empty.";
		$errors["-88"] = "Point of Sale check account number is invalid or empty.";
		$errors["-89"] = "Point of Sale check MICR invalid or empty.";
		$errors["-90"] = "Point of Sale check number missingor invalid Point of Sale check number invalid or empty.";
		$errors["-91"] = "\"Make CVV a required field feature\" enabled in the Merchant Account Setup interface but no CVV code was sent in the transaction data.";
		$errors["-92"] = "Approval Code Invalid. Approval Code is a 6 digit code.";
		$errors["-93"] = "Blind Credits Request Refused \"Allow Blind Credits\" option must be enabled on the Skipjack Merchant Account.";
		$errors["-94"] = "BlindCreditsFailed Skipjack Financial Services Skipjack Integration GuidePage 53 of 251";
		$errors["-95"] = "Voice Authorization Request Refused Voice Authorization option must be enabled on the Skipjack";
		$errors["-96"] = "Voice Authorizations Failed";
		$errors["-97"] = "Fraud Rejection Violates Velocity Settling.";
		$errors["-98"] = "Invalid Discount Amount";
		$errors["-99"] = "POS PIN Debit Pin BlockDebit-specific";
		$errors["-100"] = "POS PIN Debit Invalid Key Serial Number Debit-specific";
		$errors["-101"] = "Data for Verified by Visa/MC Secure Code is invalid.";
		$errors["-102"] = "Authentication Data Not Allowed";
		$errors["-103"] = "POS checkdateofbirth variable contains a birth date in an incorrect format. Use MM/DD/YYYY format for this variable.";
		$errors["-104"] = "POS checkidentificationtype variable contains a identificationtype value which is invalid. Use the single digit value where Social Security Number=1, Drivers License=2 for this variable.";
		$errors["-105"] = "Track Data is in invalid format.";
		$errors["-106"] = "POS Check Invalid Account Type";
		$errors["-107"] = "POS PIN Debit Invalid Sequence Number";
		$errors["-108"] = "Invalid Transaction ID";
		$errors["-109"] = "Invalid From Account Type";
		$errors["-110"] = "Pos Error Invalid To Account Type";
		$errors["-112"] = "Pos Error Invalid Auth Option";
		$errors["-113"] = "Pos Error Transaction Failed";
		$errors["-114"] = "Pos Error Invalid Incoming Eci";
		$errors["-115"] = "POS Check Invalid Check Type";
		$errors["-116"] = "POS Check lane or cash register number is invalid. Use a valid lane or cash register number that has been configured in the Skipjack Merchant Account.";
		$errors["-117"] = "POS Check Invalid Cashier Number";


		return (isset($errors[$code])) ? $errors[$code] : "Unknown Error";
	}
416574
protected function onFailure(RequestInterface $request)
    {
        return function ($reason) use ($request) {

            // Only log a rejected requests if it hasn't already been logged
            $this->log($request, null, $reason);

            return Promise\rejection_for($reason);
        };
    }
1061201
public function error(ServerRequestInterface $request, int $code = 0, string $msg = null, ...$args): ServerRequestInterface
    {
        $routing = $request->getAttribute('routing');

        if (empty($routing)) {
            return $request;
        }

        if ($msg !== null && $args !== []) {
            $msg = \sprintf($msg, ...$args);
        }

        $error = new ActionError($msg, $code);
        $forwardTo = $error->getForwardTo();
        $forwardTo['handler'] += $this->app->getRealHandler($routing['handler']);;

        return $request->withAttribute('routing', $forwardTo);
    }
277711
protected function handleException($message, $statusCode, $errorType, $errorCode, $missingParameter, $rawOutput)
    {
        if ($statusCode === 400 && $errorCode === 'rate_limit') {
            $class = 'ApiLimitExceeded';
        } elseif ($statusCode === 400 && $errorType === 'invalid_request_error') {
            $class = 'MissingParameter';
        } elseif (array_key_exists($errorType, $this->exceptionsByErrorType)) {
            $class = $this->exceptionsByErrorType[$errorType];
        } elseif (array_key_exists($statusCode, $this->exceptionsByStatusCode)) {
            $class = $this->exceptionsByStatusCode[$statusCode];
        } else {
            $class = 'Stripe';
        }

        $class = "\\Cartalyst\\Stripe\\Exception\\{$class}Exception";

        $instance = new $class($message, $statusCode);

        $instance->setErrorCode($errorCode);
        $instance->setErrorType($errorType);
        $instance->setMissingParameter($missingParameter);
        $instance->setRawOutput($rawOutput);

        throw $instance;
    }
253522
protected function newResultBuilder(bool $skipCache = false) : ResultBuilderInterface
    {
        $factory = new ResultBuilderFactory();

        return $factory->make($this, $skipCache);
    }