We report on a detailed study of the electron–exciton scattering in a GaAs quantum well (QW) with a variable density two-dimensional electron gas. Both a bare QW and a QW embedded in a GaAs/AlGaAs microcavity are studied by measuring the reflection linewidths of the bare excitons and the cavity polaritons as a function of photoexcitation intensity, temperature, and a perpendicularly applied magnetic field. This field induces the formation of charged polaritons at temperatures higher than the range of the charged exciton binding energy. The bare exciton linewidth dependence on electron density shows a transition when the electron gas transforms from classical to degenerate state. The lowest polariton linewidth dependence on electron gas and detuning energy is explained by the overlap of the cavity mode with the asymmetric exciton lineshape.