Don't switch on type but instead try to cast to error