public static function fromHttpRequestAndResponse(
        HttpRequest $request,
        HttpResponse $response
    ) {
        $message = '';
        $jsonResponse = $response->getJsonResult();

        $errors = self::parseErrorsFromResponse($response);
        if (isset($jsonResponse->type, $jsonResponse->message)) {
            $message .= $jsonResponse->message;
            if (!empty($errors)) {
                $message .= ' | ' . $errors;
            }
            return new ApiResponseException(
                $message,
                $response->getCode(),
                null,
                $request,
                $response
            );
        }

        if ($response->getMessage()) {
            $message .= $response->getMessage();
        }
        if (!empty($errors)) {
            $message .= ' | ' . $errors;
        }
        return new HttpResponseException(
            $message,
            $response->getCode(),
            null,
            $request,
            $response
        );
    }