fix onError typeError bug

N.b. MUST ADD UNIT TESTS FOR
PURITY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!