Could you log the original error from the platform and share the error message and code? I think this error is not from the platform but a custom error from the app code.
Also, share the SMI function code to replicate the issue.
What is the FDK version?
Is the Issue happening in the local simulation or production environment?
@Claret_Ivin In the app, you have the code, throw new Error("Failed to generate token"); in the catch handler for the $request.invokeTemplate() method. The same error is passed in the SMI and in the app.js file, which is what is thrown in the UI. It is expected.
Please troubleshoot what is failing in the API and causing the flow to go into the catch block. That would be your right direction to troubleshoot the failure.
The error I see comes from your code in the catch block. Check why the API fails and fix it.
We removed the code that throws a new error (“Failed to generate token”) and made the API call again, but unfortunately, we received an empty response.
We tested the API using Postman and were able to perform the call successfully.
The problem seems to arise when publishing the app as a custom app. Interestingly, the same functionality works fine in the local environment.
@Claret_Ivin The API response directly comes from your/third-party API service if the error code is not 5xx.
Could you share the complete response with the response code and body in both the FW app and from Postman/cURL?
Just in case, to find if the context is placed fine, could you test once with the path completely hard coded? After it works, it can be moved back to the context.
Could you check if the request’s URL, headers, and body are sent fine in the network tab?
Where does the config_data come from? Could you hard-code it and test it as well?
Despite attempting to hardcode the complete path and ensuring correct passing of the URL, headers, and body, we’re still receiving an empty response. Even after hardcoding the config_data values, the issue persists. However, when we tested the API call with the Axios method, we were able to receive a response.
@Claret_Ivin Unsure why the response is empty from SMI.
Could you share the app ID and approximate time of the request along with the request ID for us to check the logs and investigate further?
@Claret_Ivin We have analyzed the logs at our end. The SMI is getting successful for the app with ID 10742 at the mentioned timestamp.
We see status code 200 for the SMI, which means the SMI was successful.
The payload has what has been sent from the Serverless function. Could you check by sending a plain variable in the success payload? Then, the issue only occurs with the Request Method made in the Serverless.
The response can be completely logged to find what is being received in the Serverless logs. Then it can be fixed.
Please share the Request Method code and the request template for further help. Thanks.
@Claret_Ivin Since this transaction is happening in the installation step, it’s hard to watch the Serverless logs.
Add more logs to the API response to find what exactly is received from the API, handle the error, pass it on to the SMI, and fail it if the API fails.
Let the app installation go through even if the API fails so that the serverless logs can be read after the app installation. If the app installation fails, you don’t have a way to find the serverless logs for the app.
Summary:
The app source code and steps are shared over a personal message thread and troubleshooting is done in multiple steps due to some blockers. Finally, the issue has been found but not the cause.
Final solution: @Claret_Ivin has used Axios, which works fine in the SMI function and satisfies the requirement.
Context of the issue:
The SMI is used from the app’s Installation Parameters, and the Request Method is used within the SMI function to return a response. This has to be done securely, which cannot be done on the frontend because secure information is sent over the request body. The Request Method failed with error code 400, and the error was not handled, nor was any response sent. So, the SMI function returned an empty array as there was no response sent using the renderData() callback, and all the statements were completed execution.
Action item for the issue:
The request method returns error 400, though the request never reached the middleware server maintained by @Claret_Ivin’s team. To report this specific issue, a support ticket has been raised (https://support.freshdesk.com/support/tickets/16080760).