How to Record API Function Stack Errors for Later Analysis

Options

HI, I am builing API function stacks, but want to log to the database a meaningful message if something on the function stack creates an error.

Because under normal circumstances, if my front end sends data thats not quite right or I make a mistake in the function stack and it creates an error, how can the error be caught and analysed when the system in in production?

I have a helper global function that can write to my error log table, but when the function stack halts doe to an error I can't seem to save this error in any controlled way.

What I see is the error sent back to the front end to deal with but how can the error be recorded anyway in the backend?

Thanking you

Answers

  • lesa
    lesa Member, Administrator

    ADMIN

    Options

    Hey Ken

    Have you tried using a Try/Catch for this? Here's a video about it.

  • KenJ
    KenJ Member
    Options

    Hi, I see Try/Catch is wrapped around functions.

    But I am finding the error occurs sometimes right up front for example when an integer input receives a text input value and this instantly triggers an ERROR.

    I cant see how Try/Catch can intercept this type of ERROR or is there some other way to catch these errors?

    Thanking you,

  • sweekark
    sweekark Member
    Options

    Yes i dont think you can catch parameter validations using try/catch, and i think this would be a frontend error because the input from the frontend is wrong and imo i dont think we have to log this.😀

    however you can wrap your whole api function in try/catch and use throw to send the error msg and code.