Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cloud_functions] HttpsCallable.call throws PlatformException instead of CloudFunctionsException #2069

Closed
punkeroso opened this issue Feb 27, 2020 · 12 comments
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: functions type: bug Something isn't working

Comments

@punkeroso
Copy link

punkeroso commented Feb 27, 2020

Describe the bug
When calling .call trying to get an error (i.e. with wrong parameters, wrong function name or wrong region) I'm getting a PlatformException instead of a CloudFunctionsException

To Reproduce
This is the function that actually call .call

Future<num> _simpleFunction(String param1, String param2) async {
    final HttpsCallable _simpleFunction =
        CloudFunctions(region: "europe-west1")
            .getHttpsCallable(functionName: 'simpleFunction');

    try {
      final HttpsCallableResult response = await _addUserRemainder
          .call(<String, dynamic>{'param1': param1, 'param2': param2});

      return response.data['result'];
    } on CloudFunctionsException catch (e) {
      print('catched $e');
      rethrow;
    }
}

And this is where I call _simpleFunction

try {
        num balance;
          balance =
              await _simpleFunction('param', 'param2');
        }
      } catch (error) {
        print('Main block $error');
      }

And I always get:
I/flutter (10343): Main block PlatformException(functionsError, Cloud function failed with exception., {code: INVALID_ARGUMENT, details: null, message: Invalid QR code})

Expected behavior
Reading the implementation of .call function, it should always return a CloudFunctionsException instead.

Additional context
cloud_functions version is 0.4.2

Till the version 0.4.1+6 was working fine.

@punkeroso punkeroso added the type: bug Something isn't working label Feb 27, 2020
@dftorres
Copy link

Any update on this? I'm having the same issue.
I read this stack overflow question and it says that the cloud functions api can only throw HttpsError with certain codes, that flutter can't catch because there isn't a "functionsError" code. I can't change the implementation of the Cloud Function to throw a generic error with "functionsError" code. I need help

@kirstywilliams kirstywilliams added impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: functions labels Apr 21, 2020
@ElZombieIsra
Copy link

Is there info if this is going to be fixed? I have the same issue

@mrsavari
Copy link

mrsavari commented Jun 1, 2020

the same here

@kikuchy
Copy link

kikuchy commented Jun 10, 2020

I fixed it at this issue #2556 but anyone reviewed it.

@yamauchieduardo
Copy link

yamauchieduardo commented Jul 8, 2020

6 months and the bug stays, this behaviour break all my tests. Waiting for #2556 pull request being aproved. @Salakar @collinjackson @kroikie

@cristianm
Copy link

Same error here!!

@cubuspl42
Copy link
Contributor

@TahaTesser Could I kindly ping you? This is issue is quite problematic and there's a ready PR (two, actually). The only thing this issue needs is a little bit of ❤️

@TahaTesser
Copy link

@cubuspl42
Thanks for the info, will let the team know

@tzvc
Copy link

tzvc commented Jan 14, 2021

Any updates on this ? Happy to help if PR review is needed :)

@diegogarciar
Copy link
Contributor

diegogarciar commented Jan 14, 2021

It is working for me but using FirebaseFunctionsException not CloudFunctionsException

Future<T> _call<T>(String name, Map params) async {
    print('functions._call, $name, $params');
    final HttpsCallable callable = _cf.httpsCallable(name);
    try {
      final result = await callable.call(params);
      print(result.data);
      return result.data;
    } on FirebaseFunctionsException catch (e) {
      print('caught firebase functions exception');
      print(e.code);
      print(e.message);
      print(e.details);
      if (e.details == null) {
        throw "Unknown error occurred";
      }
      print(e.details["message"]);
      if (e.details["code"] == "some_code") {
        throw "Some Error";
      }
      throw e.details["message"];
    } on PlatformException catch (e) {
      print(e.message);
      print(e.details);
      final cloudException = e.details;
      throw cloudException["message"];
    } catch (e) {
      print(e);
      throw "Unknown error";
    }
  }

@cubuspl42
Copy link
Contributor

AFAIK, it's fixed in upstream.

@Salakar
Copy link
Member

Salakar commented Apr 21, 2021

This has been fixed a while back, please try the latest release, thanks.

@Salakar Salakar closed this as completed Apr 21, 2021
@firebase firebase locked and limited conversation to collaborators May 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: functions type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests