Integrate $\int \frac{1}{1+\sin x}\: dx$ using substitution $u=1+\sin x$ I'm trying to work out what went wrong with the following method and how I can precisely correct it.
MY ATTEMPT:
\begin{align*}
\text{Let } u&=1+\sin x\\
\therefore du&=\cos x\:dx\\
&= \pm\sqrt{1-\sin^2x}\:dx\\
&= \pm\sqrt{1-(u-1)^2}\:dx\\
&=\pm \sqrt{2u-u^2}\:dx\\
\therefore dx&= \dfrac{du}{\pm \sqrt{2u-u^2}}
\end{align*}
\begin{align*}
\therefore \int \dfrac{1}{1+\sin x}\: dx &= \pm \int \dfrac{1}{u} \times \dfrac{1}{\sqrt{2u-u^2}} \: du\\
&= \pm \int \dfrac{1}{u^2\sqrt{2/u -1}} \: du\\
&= \pm \int \dfrac{1}{u^2} \times \left( \dfrac{2}{u}-1 \right)^{-1/2}\: du\\
&=\pm \dfrac{1}{2} \int \dfrac{2}{u^2} \times \left( \dfrac{2}{u}-1 \right)^{-1/2}\: du\\
&= \mp \dfrac{1}{2} \times 2\times \sqrt{\left(\dfrac{2}{u}-1\right)} + C\\
&= \mp \sqrt{\dfrac{2}{1+\sin x}-1}+C
\end{align*}
My final answer seems to be the absolute value of one of the primitives of $\dfrac{1}{1+\sin x}$. I know that having the $\pm$ in the $u$-sub is not ideal, but I left it there because I wasn't sure how to address it correctly. From my experience, these problems usually occur because the substitution was of the form $x=f(u)$ instead of $u=g(x)$. But in my method, the latter is used...
Question: How can I properly address this issue?
P.S. Yes, I know there are better ways (Weierstrass sub and clever manipulations) to approach this integral. I just want to know how to properly use this approach.

Note that $
du=\cos x\:dx= \text{sgn}(\cos x)\sqrt{2u-u^2}dx
$
and your solution is
\begin{align*}
\int \dfrac{1}{1+\sin x}\: dx &= \text{sgn}(\cos x) \int \dfrac{1}{u} \times \dfrac{1}{\sqrt{2u-u^2}} \: du\\
&= - \text{sgn}(\cos x)\sqrt{\dfrac{2}{1+\sin x}-1}+C\\
 &= - \text{sgn}(\cos x)\sqrt{\dfrac{1-\sin x}{1+\sin x}}+C\\
 &= - \text{sgn}(\cos x){\dfrac{|\cos x|}{1+\sin x}}+C\\
 &= - {\dfrac{\cos x}{1+\sin x}}+C
\end{align*}
