Problems Using Catch/Response for an API

So I have an API which is throwing a 422 response that I want to tell my user about, but I cannot make the error message I am defining on the Server Side come through to the Client Side.

Here is my server side code (I’m not sure if the Response should go in the Steps or Catch area, so I have it in both for now):

422-2

And here is what I get back on the client side:

So I am clearly creating a 422 error, but the message is always just “422” and not the message I am setting in my response action step…

And I’m not sure what the response field of the Last Error should contain… would that contain the response from the API, so this JSON…?

422-3

Is there something sensible I can do to capture the “Message” field of error response and show it to the user?

Best wishes,
Antony.

PS - so if I then want further Server Action steps to only occur if the response is 200, how do I specify that in a condition? :thinking:

1 Like

Hi Antony, there is a thread here with an example of capturing the error details - in case it helps.

Thanks @TomD… I have already crawled all over that and related posts and they don’t seem to provide the solution…

Hi Antony, I'm using 500 responses on server connect with messages, no problems.

Try removing the quote marks in the Text field...

On the front end I'm using a flow with an Alert (bootbox) to display the 'response'

Thanks for those thoughts Max!

I’ve removed the quotes, but it is still the same response. Just to be sure I’m not going crazy I’ve checked the data I am displaying in red, which look okay to me…

422-4

Mine is an API rather than a database connection, so I’m wondering if that makes a difference, or whether I have uncovered a bug…

Strange as believe it or not mine is using the Postmark API too. All I display to the user is the error response rather than name or status.

I haven’t tested this inside of a catch step yet. Mine responses are inside of a condition else clause.

Coincidence!

What does you condition test then?

It looks like your response display is referencing the name of the api action in the server connect, however shouldn’t it reference the name of the app connect action on the front end? In other words, the response is what you should reference, not the output of the api action.

Checks if the user has been verified already, then checks to make sure they haven't requested a verification link within the last 2 minutes, then generates a hash and sends an email to the user with a link to verify their account.

1 Like

Hello Ken! :slight_smile:

Well that is true, except to say that actually the server connect, the server action and the api action are all called register_postmark_email.

I’d be interested to hear your views on that being the case… I believed that the only thing accessible on the front end is from the server connect so it wouldn’t be an issue.

I tried renaming the server connect to be sc_register_postmark_email and the problem persists.

I did get the API to produce a 503 error a short while ago and the error message for that came through, so I am a bit baffled as to what is going on.

Do these response items go in the Steps area or the Catch area, or doesn’t it matter?

I don’t think the naming is the issue, although I typically don’t use that naming convention.

My experience has been that when the response action step is used, it becomes the only output. However what you are showing with the object object, suggests that is coming from the api action – the text in the response properties is a simple text field.

If you in your testing saw the 503 and its description, while still having the 422 in the response action, that suggests you were looking at the result of the api, not the response.

I’d trim this all back to just the response action so you can see that it is properly making it to the front end.

2 Likes

I think our new upcoming try-catch action might come handy here.

With it you can check for a single action if it fails or not.

We have made it for the flows first but will see if we can do it for server connect as well @patrick

2 Likes