add error handling with typed api errors