src/Judopay/Exception/ApiException.php
public static function factory(ResponseInterface $response)
    {
        $parsedBody = $response->json();

        $category = ArrayHelper::get(
            $parsedBody,
            'category',
            static::CATEGORY_UNKNOWN
        );

        $message = ArrayHelper::get($parsedBody, 'message', get_called_class());

        $errorCode = ArrayHelper::get($parsedBody, 'code', 0);

        $fieldErrors = array();

        if (isset($parsedBody['details']['receiptId'])) {
            //Convert receiptId to a non scientific notation
            $fReceiptId = sprintf('%f', $parsedBody['details']['receiptId']);
            $iReceiptId = rtrim($fReceiptId, '0');
            //De-deduplicate format
            $message .= ' Duplicate receipt id: '. $iReceiptId;
        } elseif (isset($parsedBody['details']) && is_array($parsedBody['details'])) {
            //Regular 'model errors' format
            foreach ($parsedBody['details'] as $rawFieldError) {
                $fieldErrors[] = new FieldError(
                    ArrayHelper::get($rawFieldError, 'message', ''),
                    ArrayHelper::get($rawFieldError, 'code', 0),
                    ArrayHelper::get($rawFieldError, 'fieldName', ''),
                    ArrayHelper::get($rawFieldError, 'detail')
                );
            }
        }

        $statusCode = $response->getStatusCode();

        return new static(
            $message,
            $errorCode,
            $statusCode,
            $category,
            $fieldErrors
        );
    }
public static function factory(ResponseInterface $response)
    {
        $parsedBody = $response->json();

        $category = ArrayHelper::get(
            $parsedBody,
            'category',
            static::CATEGORY_UNKNOWN
        );

        $message = ArrayHelper::get($parsedBody, 'message', get_called_class());

        $errorCode = ArrayHelper::get($parsedBody, 'code', 0);

        $fieldErrors = array();

        if (isset($parsedBody['details']['receiptId'])) {
            //Convert receiptId to a non scientific notation
            $fReceiptId = sprintf('%f', $parsedBody['details']['receiptId']);
            $iReceiptId = rtrim($fReceiptId, '0');
            //De-deduplicate format
            $message .= ' Duplicate receipt id: '. $iReceiptId;
        } elseif (isset($parsedBody['details']) && is_array($parsedBody['details'])) {
            //Regular 'model errors' format
            foreach ($parsedBody['details'] as $rawFieldError) {
                $fieldErrors[] = new FieldError(
                    ArrayHelper::get($rawFieldError, 'message', ''),
                    ArrayHelper::get($rawFieldError, 'code', 0),
                    ArrayHelper::get($rawFieldError, 'fieldName', ''),
                    ArrayHelper::get($rawFieldError, 'detail')
                );
            }
        }

        $statusCode = $response->getStatusCode();

        return new static(
            $message,
            $errorCode,
            $statusCode,
            $category,
            $fieldErrors
        );
    }
Factory method
@param ResponseInterface $response
@return static