Integration by substitution fail for $\int \frac{1}{(1+\sin x)}\, \mathrm dx$. We tried to do an integral with the universal trigonometric substitution $$\int \frac{1}{(1+\sin x)}\, \mathrm dx$$
Meaning, we substituted: $ t = \tan \frac{x}{2}  \Rightarrow$ 
$$\int \frac{1}{(1+\sin x)}\, \mathrm dx = \int \frac{\frac{2}{1+t^2}}{1+\frac{2t}{1+t^2}}\, \mathrm dt = \int \frac{2}{(1+t)^2}\, \mathrm dt = \frac{-2}{1+t} = \frac{-2}{1+\tan \frac{x}{2}} + C$$
But the answer is:
$$ \tan x - \frac{1}{\cos x} + C $$
What did we do wrong?

Another approach would be to first multiply the integrand by $\dfrac{1-\sin x}{1-\sin x}$ to get
$$\begin{aligned}\int \frac{1}{1+\sin x}\,dx &= \int\frac{1-\sin x}{1-\sin^2 x}\,dx\\ &= \int\frac{1-\sin x}{\cos^2x}\,dx \\ &= \int\frac{1}{\cos^2 x}-\frac{\sin x}{\cos^2 x}\,dx \\ &= \int \sec^2x -\frac{\sin x}{\cos^2x}\,dx\\ &= \ldots\end{aligned}$$
The first term is trivial to integrate, and the second integral requires the substitution $u=\cos x$.  I leave it to you to finish things off.
