Can't find why the proof is false (substitution rule). Statement: Suppose $f$ and $g$ are functions with domain $\mathbb{R}$ and we want to show that if 
$$\lim_{x \rightarrow a} f(x) = b\ \ \text{and}\ \lim_{x \rightarrow b} g(x) = c,\ \text{then}\ \lim_{x \rightarrow a} g(f(x)) = c.$$

I know that this statement is false $\bigg($let $f(x)=0$ and $g(x)=\begin{cases}1&x= 0\\0&x\neq0\end{cases}$, as $x\to 0$$\bigg)$.
But I don't understand where the following attempt to prove the statement fails.

"Proof": 
Since $\lim_{x \rightarrow b} g(x) = c$, $$\forall\epsilon>0,\ \exists\delta_1,\ 0<|x-b|<\delta_1\Rightarrow |g(x)-c|<\epsilon.\tag 1$$
Since $\lim_{x \rightarrow a} f(x) = b$, we can choose $\delta_2$ such that $$0<|x-a|<\delta_2\Rightarrow |f(x)-b|<\delta_1.$$
Now, using implication $(1)$,
$$\forall\epsilon>0,\ \exists\delta_2,\ 0<|x-a|<\delta_2\Rightarrow |f(x)-b|<\delta_1 \Rightarrow |g(f(x))-c|<\epsilon,$$ which is $\lim_{x \rightarrow a} g(f(x)) = c$.

The only suspicious point that I see is that to use $(1)$, it should be the case that $f(x)\neq b$.
But the counterexample relies on the discontinuity of $g$.
 A: The problem point was applying implication $(1)$ to obtain $$|f(x)-b|<\delta_1 \Rightarrow |g(f(x))-c|<\epsilon,$$ since it could be that $f(x)=b$, and $$0<|x-a|<\delta_2\Rightarrow |f(x)-b|<\delta_1 \not \Rightarrow 0<|f(x)-b|<\delta_1,$$ as @Henry pointed out in comments.

So, if we would add the requirement that $f(x)\neq b$ as $x\to a$, we're done.

I was initially confused by the discontinuity of $g$ at $b$ in the counterexample, and the requirement of continuity of $g$ at $b$ in some answers to similar questions, like this.
As it turns out, this requirement addresses the same thing. Suppose we know that $g$ is indeed continuous at $b$, $\lim_{x \rightarrow b} g(x) = g(b) = c$, so the implication $(1)$ is $$\forall\epsilon>0,\ \exists\delta_1,\ 0<|x-b|<\delta_1\Rightarrow |g(x)-g(b)|<\epsilon.\tag 2$$ 
Now, in the case of $x=b$, $|x-b|=0<\delta_1$ and $g(x)=g(b)$, so $|g(x)-g(b)|=0<\epsilon$. So $(2)$ becomes $$\forall\epsilon>0,\ \exists\delta_1,\ |x-b|<\delta_1 \Rightarrow |g(x)-g(b)|=|g(x)-c|<\epsilon,$$ which can be used in place of $(1)$ in the proof.

Conclusion: In order to make the original statement true, we can add hypothesis that $f(x)\neq b$ as $x\to a$, or that $g$ is continuous at $b$, $\lim_{x \rightarrow b} g(x) = g(b) = c$.
