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 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 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”).