private function parseErrorResponse(PsrRequest $request, BadResponseException $ex)
    {
        try {
            $response = $ex->getResponse();
            $document = $response ? $this->factory->createDocumentObject($request, $response) : null;
            $errors = $document ? $document->getErrors() : [];
            $statusCode = $response ? $response->getStatusCode() : 0;
        } catch (Exception $e) {
            $errors = [];
            $statusCode = 0;
        }

        return new JsonApiException($errors, $statusCode, $ex);
    }