Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
This method is used to obtain the result codes of Firebase Functions exceptions. The return value is a code of the enum type, while that of AGCFunctionException.getCode() in AppGallery Connect is of the int type. AppGallery Connect does not have so many types of possible errors as defined in Firebase, and common errors are contained in various exception types. Therefore, when using AppGallery Connect, you can capture error messages using various types of common exceptions.
When the getCode() method of Firebase is used:
try {
// ...
} catch (FirebaseFunctionsException e){
FirebaseFunctionsException.Code code = e.getCode();
// ...
} The following is an example of code modification in the Add HMS API policy (after the conversion, the generated XMS Adapter module contains the GlobalEnvSetting and other classes):
try {
// ...
} catch (ExtensionFunctionsException e){
if (GlobalEnvSetting.isHms()) {
int code = ((com.huawei.agconnect.function.AGCFunctionException) e.getHInstance()).getCode();
} else {
FirebaseFunctionsException.Code code = ((com.google.firebase.functions.FirebaseFunctionsException) e.getGInstance()).getCode();
}
} The following is an example of code modification in the To HMS API policy:
try {
// ...
} catch (AGCFunctionException e){
int code = e.getCode();
// ...
} getInstance(FirebaseApp app) creates a Cloud Functions client using a given app.
getInstance(FirebaseApp app, String region) creates a Cloud Functions client using a given app and region.
getInstance(String region) creates a Cloud Functions client using the default app and a specified region.
In Firebase, getInstance in the preceding methods is implemented with parameters, but without parameters in AppGallery Connect. The following provides the simplified sample code.
When the getInstance() method of Firebase is used:
HttpsCallableReference httpsCallableReference = FirebaseFunctions.getInstance().getHttpsCallable("test0");
HttpsCallableReference httpsCallableReference = FirebaseFunctions.getInstance("test1").getHttpsCallable("test1");
HttpsCallableReference httpsCallableReference = FirebaseFunctions.getInstance(FirebaseApp.getInstance()).getHttpsCallable("test2");
HttpsCallableReference httpsCallableReference = FirebaseFunctions.getInstance(FirebaseApp.getInstance(), "test3").getHttpsCallable("test3"); The following is an example of code modification in the To HMS API policy:
FunctionCallable httpsCallableReference = AGConnectFunction.getInstance().wrap("test0");
FunctionCallable httpsCallableReference = AGConnectFunction.getInstance().wrap("test1");
FunctionCallable httpsCallableReference = AGConnectFunction.getInstance().wrap("test2");
FunctionCallable httpsCallableReference = AGConnectFunction.getInstance().wrap("test3"); This method is used to call a local function simulator to help developers test cloud functions. In AppGallery Connect, you do not need to add code to your program. Instead, you only need to perform some web operations for function testing. For details, please refer to Testing a Function.