datastore: Handle key and query related problems before making the request.