better api errors handling