How to handle errors in HTTP Post request

I am making a post request to an external API - in case, I get an error I want to return the error along with the error.response.data that axios typically has to the caller. How do I do this in the HTTP post request as I could not see any reference to the error there?

Update after a few hours of research and trials : I figured out that the platform-version of axios returns response.data directly if the call is successful and returns the error and the full axios object. I now need to reference this in the next step. But the execution is ending here. Am I supposed to execute try-catch in this step to test whether there are errors? Since I don’t have access to code here, just params, I can’t see anything related to error-handling except sending it to global error workflow.

@siraj-samsudeen That’s correct. If a step throws an error in a Pipedream workflow, we end the execution at that step. If you need the workflow to continue and handle the error data in a custom way, I’d recommend running your own Node.js code and making an HTTP request there. That way, you can implement your own try / catch logic. You can also modify the validateStatus option to change how axios throws on HTTP errors.

Let me know if that helps.

Hi Dylan, thanks for the response. I would try implementing my own Node.js logic. But I am surprised that noone else had the need to handle the error in the HTTP Post request action.

Yes I hear you completely. We plan to improve the ability to handle errors for actions natively (imagine a UI for try / catch). I think that’ll help simplify this in the future.

+1 was looking for this information

I simply changed all my HTTP Post request blocks to Node, but maybe it will be good to add a note when creating the block (“this block ends on an error response, if you want to catch/handle errors, create a custom Nodejs block instead”).

Hi Dylan, did Pipedream ever get around to building the try catch logic for HTTP Post requests? It doesn’t seem like it but I wanted to ask before spending a bunch of time Changing them all to Nodejs blocks and updating everything that referenced those blocks to reference the new blocks.

@aaron Since this post we’ve shipped a new set of HTTP actions that handle some errors, auto-retry, and a few other related features. What try / catch logic would you like to implement in this case? Happy to point you in the right direction.

Hi @dylburger thanks for getting back to me. An example is an http post which works fine normally but needs to account for errors like Error Request failed with status code 400. When that happens I need to be able to capture that error in the step to use in another step but when an error occurs the flow stops and I cannot take any actions after that as a result. I can write it in a node block but wanted to see if it could continue but log the error as a step output and allow the flow to continue.

Got it thanks. Today it’s not possible to try / catch an action like this from the UI like you’re thinking, but we’re working on better flow control (branching, looping, try / catch logic) to support this! For now you will need to handle in code.