Пакет Flutter Firebase cloud_functions выдает ошибку: ВНУТРЕННЯЯ - PullRequest
1 голос
/ 02 октября 2019

При попытке вызвать функцию облака я получаю «CloudFunctionsException»

  • Код исключения: «ВНУТРЕННИЙ
  • ». Сообщение «Ответ недействителен». Объект JSON. "

enter image description here Опишите ошибку

Воспроизвести Шаги для воспроизведения поведения: - Мой вызов из приложения

 HttpsCallable _getName;

 _getName = CloudFunctions.instance.getHttpsCallable(functionName: 'getName',);


 try {
      HttpsCallableResult resp = await _getName.call(<String, dynamic>{'name': name,});
      Scaffold.of(context).showSnackBar(SnackBar(content: Text("${resp.data}")));
    } on CloudFunctionsException catch  (e) {
      showErrorMessage(context, 'Cloud functions exception with code: ${e.code}, and Details: ${e.details}, with message: ${e.message} ');
    } catch (e) {
      showErrorMessage(context, e.toString());
    }
  • Функция My Cloud написана так:
exports.getName = functions.https.onCall((data, context) => {
    return {
        "data" : "You hit the call at least!"
    };
});

Ожидаемое поведение В моемВ ответ я должен получить данные: «Вы нажали тестовый вызов». Вместо этого я получаю сообщение об ошибке

Дополнительный контекст Когда я выполняю вызовы той же функции, но с пакетом HTTPи получить его на стороне с помощью «onRequest», он работает.

  void _checkPersonsNameGET(String name)async{
    try {
      http.Response resp = await http.get(_cloudFunctionUrl,,  );
      _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("${resp.body}", style: TextStyle(color: Colors.green))));
    } catch (e) {
      showErrorMessage(context, e.toString());
    }
  }

  void _checkPersonsNamePOST(String name)async{
    try {
      http.Response resp = await http.post(_cloudFunctionUrl, body: { "name" : name } );
      _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("${resp.body}", style: TextStyle(color: Colors.green))));
    } catch (e) {
      showErrorMessage(context, e.toString());
    }
  }
exports.getName = functions.https.onRequest((request, response) => {

    const name = request.query.name || request.body.name;
    switch (name) {
        case 'Andrew':
            request.query.name ? response.send("Na he is the boi Q!") : response.send("Na he is the boi B!");
            break;

        case 'Brett':
            request.query.name ? response.send("Na just wierd! Q") : response.send("Na just wierd! B");
            break;

        case 'Eddie':
            request.query.name ? response.send("My brother but yeah! Q") : response.send("My brother but yeah! B");
            break;

        case 'James':
            request.query.name ? response.send("The biggest! Q") : response.send("The biggest! B");
            break;

        default:
            request.query.name ? response.send("Dunno who that is! Q") : response.send("Dunno who that is! B");
            break;
    }
});

Это ложное приложение и его можно увидеть здесь https://github.com/earyzhe/firebase_cloud_functions_play

...