integrationflowgear

Flowgear send sucess and error response using FgResponseBody and FgResponseStatusCode


I want to send success and error responses based on a condition. For example, I took a variable called a using the variable section and I needed to return the success & failure responses.

enter image description here

If I am trying to add two FgResponseBody sections, I get an error saying it can't be used more than one time.

Also, using Error node Can I return custom json message??


Solution

  • When you are building API workflows in Flowgear, there is no need to have two FgResponseBody properties on your output Variable bar. You need to make sure that the flow you are building always has one outcome (Success or failure).

    If for whatever reason you need to return Success and Failure in a json response, I would suggest that you combine those responses into 1 json body which can be plugged into one FgResponseBody property on your output variable bar. Here is a simple example:

    { "SuccessMessage": [{Message For Success Here}], "FailureMessage": [{Message For Failure Here}] }

    On the Error node. This is just used to present a custom message on the node when it fires. So if you send data down a stream after an error is caught, this message will be presented on an error node that makes it easy to find in the Activity Logs. The ErrorMessage property data type is text, but it will take a json message if it is passed in.

    Below is an example of how to combine your json messages into one. The first screenshot shows you a very simple json object with one field called message. This message indicates my success. Keep in mind that this message does not have to come from a formatter, but I am using it to illustrate a message being caught.

    Simple Json body with Success Message

    Here I am doing the same thing, but it is a message for failure.

    Simple Json body with Failed message

    In the screenshot below this section, I used Flowgear variables in another Formatter. A variable in Flowgear is used like this: {variable_name_here}. The variable name being used in your expression will need to be the same name as your property on the node. I then created another simple json body to wrap the two messages into one body.

    Json body to combine messages

    The result of the above will look like this:

    Result