public static function getErrorDetails(ResponseInterface $response)
    {
        $responseInfoProperties = [
            // Platform.sh API errors.
            'message',
            'detail',
            // RESTful module errors.
            'title',
            'type',
            // OAuth2 errors.
            'error',
            'error_description',
        ];

        $details = '';

        $response->getBody()->seek(0);
        $contents = $response->getBody()->getContents();

        try {
            $json = \GuzzleHttp\json_decode($contents, true);
            foreach ($responseInfoProperties as $property) {
                if (!empty($json[$property])) {
                    $value = $json[$property];
                    $details .= " [$property] " . (is_scalar($value) ? $value : json_encode($value));
                }
            }
        } catch (\InvalidArgumentException $parseException) {
            // Occasionally the response body may not be JSON.
            if ($contents) {
                $details .= " [extra] Non-JSON response body";
                $details .= " [body] " . $contents;
            }
            else {
                $details .= " [extra] Empty response body";
            }
        }

        return $details;
    }