public function getClosePayload($e, $masked = true)
    {
        $code = false;

        if ($e instanceof Exception) {
            $code = $e->getCode();
        } elseif (is_numeric($e)) {
            $code = (int)$e;
        }

        if (!$code || !key_exists($code, self::CLOSE_REASONS)) {
            $code = self::CLOSE_UNEXPECTED;
        }

        $body = pack('n', $code) . self::CLOSE_REASONS[$code];

        $payload = $this->getPayload();
        return $payload->encode($body, self::TYPE_CLOSE, $masked);
    }