Scheduled Actions and error reporting

I am having a few troubles with Error reporting on scheduled server actions.

Scenario, I have a Library action that calls 3 different APIs from various providers as well as reads and writes to and from various database tables.

If any error happens I would like the script to stop processing and to write an entry into a database table with the error it encountered.

I have tried with Pass Errors enabled on the API actions, and that stops the script on error, but does not write anything to my database table showing the error because the script stopped so it never got to the next action.

I have put the API action in a try/catch step, and added the database insert into the catch area, and that also does not work while Pass Errors in enabled.

I have turned off Pass Errors while still inside a try/catch step, but then it never stops the script, and also never runs what is inside the Catch step.

This all stems from this thread API Action Throw Error Option

The only solution I have found is to not use try/catch, add my API action, turn off Pass Errors, and to add a condition step after, checking for requestStatus from the API return, and if true writing the error to my database, and then adding a server response 500 step to stop the rest of the server action from running. This works, however adds a lot of steps to my script if I need to add a condition and a database insert/update and a server response for every API interaction i have inside the script.

This also does not account for any and all errors that could possibly happen, such as a database insert/update error.

Is there any way to do this differently, where regardless of which step fails, whether an API failure or a database error the error can be inserted into my database once the server action stops, or have I just confused myself somewhere along the line.

1 Like

I don’t think you’re confused. :slight_smile:

I think you’re solution is the way you’ll have to go for now, although I would throw it in a library so you can have a single place to evaluate the api response for all api’s.

The library to evaluate the response. It logs the error and throws a response with the error code received:

Calling your api:

Passing the response to the evaluation library:

2 Likes

Very nice idea Ken, thanks so much for the input on this one.

So after also chatting with @sid, he also suggested adding in some try/catch actions to catch database related errors, and then this solution for evaluating status returned by APIs, and that way hopefully if my scheduler does have an error I should have a good logged error in my database to figure out where and what broke the normally working server action.

Thanks again, will get this implemented now and test it all out.

Exactly.

1 Like

Would be so nice if I could just output exactly what it would normally output to the browser if I ran the script manually, but write it into a database, even if truncated. I mean the same error shows in browser or in server when i look at the logs inside portainer, I just have no clue if there is some way to access that data, would save adding a few steps for every step in my server action, which makes it a pretty large looking script.

A comprehensive wappler solution for logging/debugging would be nice. It’ll happen some day.

3 Likes

We should maybe add an extra option Throw Errors to the action. The Pass Errors also throws an error but it also sends the error to the client and when content is already being send to the client it ignores all actions coming after that, including the ones in the catch.

2 Likes

I think you have our support. :grin: