Example 4 Find the range of the function $y=\frac{x^{2}+x-2}{x^{2}-3 x+2}$.

Translate the above text into English, please retain the original text's line breaks and format, and output the translation result directly. 

Example 4 Find the range of the function $y=\frac{x^{2}+x-2}{x^{2}-3 x+2}$.
Solve the functional transformation as
$$
(y-1) x^{2}-(3 y+1) x+2 y+2=0
$$

When $y=1$, equation (4) becomes $-4 x+4=0$, solving for $x=1$ which is not in the domain of the function, $\therefore y=1$ is not in the range of the function;

When $y \neq 1$, $\because$ the equation has real roots, $\therefore \Delta=(3 y+1)^{2}-4(y-1)(2 y+2) \geqslant 0$ which simplifies to $(y+3)^{2} \geqslant 0$, and this inequality always holds. $\therefore y \in \mathbf{R}$ and $y \neq 1$. However, when $\Delta=0$ i.e., $y=-3$, the solution of equation (4) is $x=1$ which is not in the domain of the function.