Refactor toThrowError to be less one huge if/else if/else if block

- This should also improve it's code climate score as well.
- It's also about 20 lines shorter now too :)

[#59524164]
Merge branch 'toThrowError_refactor'