cct-marketing/rest-exception-handler

An exception handler used to handle and parse all errors from the rest lib requests

v2.0.0 2023-10-05 13:16 UTC

This package is auto-updated.

Last update: 2024-11-05 15:47:04 UTC


README

An exception handler using the decorator pattern to wrap the client requests from the REST lib and parse the server responses in correctly correctly form format exceptions based on api format

Installation

composer require cct-marketing/rest-execption-handler

Usage

use CCT\Component\Rest\AbstractClient;
use CCT\Component\Rest\Config;

class RESTClient extends AbstractClient
{
    /**
     * @return ScrapeRequest
     */
    public function myAPI(): MyRequest
    {
        $config = clone $this->config;
        $modelClass = TestModel::class;

        $serializer = $this->getBuiltSerializer($config);
        if ($this->shouldUseDefaultResponseTransformers() && null !== $serializer) {
            $this->applyDefaultResponseTransformers($config, $serializer, $modelClass);
        }

        return $this->createRequestInstance(TestRequest::class, $config, null);
    }
}