Skip to content

Why the execute function on APIOperationBase class does not return the response? #69

Open
@comeacross1989

Description

@comeacross1989

Hi, I'm using a firebase callable function and would like to send the repsponse back to the client once the transaction is completed - instead of sending another post to a different URL. The only problem is that the APIOperationBase.execute does not return the response.
Is there a reason for this?

It would be much more efficient if I could do this...
` try {

    const THE_RESPONSE_FOR_CLIENT = ctrl.execute(function(){

        var apiResponse = ctrl.getResponse();
        var response = new ApiContracts.CreateTransactionResponse(apiResponse);

        //pretty print response
        console.log(JSON.stringify(response, null, 2));

        if(response != null){
            if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK){
                if(response.getTransactionResponse().getMessages() != null){
                    console.log('Successfully created transaction with Transaction ID: ' + response.getTransactionResponse().getTransId());
                    console.log('Response Code: ' + response.getTransactionResponse().getResponseCode());
                    console.log('Message Code: ' + response.getTransactionResponse().getMessages().getMessage()[0].getCode());
                    console.log('Description: ' + response.getTransactionResponse().getMessages().getMessage()[0].getDescription());
                    
                   
                }
                else {
                    console.log('Failed Transaction.');
                    if(response.getTransactionResponse().getErrors() != null){
                        console.log('Error Code: ' + response.getTransactionResponse().getErrors().getError()[0].getErrorCode());
                        console.log('Error message: ' + response.getTransactionResponse().getErrors().getError()[0].getErrorText());
                        
                      }
                }
            }
            else {
                console.log('Failed Transaction. ');
                if(response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null){
                
                    console.log('Error Code: ' + response.getTransactionResponse().getErrors().getError()[0].getErrorCode());
                    console.log('Error message: ' + response.getTransactionResponse().getErrors().getError()[0].getErrorText());
                    
                  }
                else {
                    console.log('Error Code: ' + response.getMessages().getMessage()[0].getCode());
                    console.log('Error message: ' + response.getMessages().getMessage()[0].getText());
                   
                  }
            }
        }
        else {
            console.log('Null Response.');  
        }
        callback(response,finalMessage);
        console.log('response,finalMessage');
        console.log(ctrl._response );
    });


    return THE_RESPONSE_FOR_CLIENT;
} catch (error) {
    throw new functions.https.HttpsError('unknown', error);
}`

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions