handle api errors