Try Catch on External API Call

Options

I am using Try/Catch on an external API call (actually an internal call) with the Catch block calling another external API call (internal call) if the first one fails. I've tried erroring out with a precondition, as well as throwing an error with a return value. In the former case, I just see the error from the Try block an the Catch never executes - ditto with throwing an error. If I return that value within the Try block, it always executes the Catch block.

Is there any way to get Try Catch to work with external API call functions?

For reference, I am using internal calls because I have an "optional authentication" user facing endpoint where different data is returned (or none at all) depending upon authentication and parameters provided (4 different permission sources with 2 tiers of access).

Comments

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    Hey, @cw. Try/Catch will never react as expected with an external API call because that function will never return an error that would halt your function stack execution. If you need different behaviors based on the result of an external API call, using a Conditional If/Then statement would be the way to go.

  • cw
    cw Member
    Options

    That works - thank you!