try/catch, switch/case

Options
Adding these features to Xano would make "coding" even more enjoyable.

Comments

  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
    100% agree - they are coming!
  • I second that emotion!!  My use case:

    Rather than multiple functions to handle customer data, I'm creating 1 role-based CRUD function to simplify managing future role additions to managing customer data.

    One case switch operator and bye bye multiple conditional statements [image.png]
  • Achin Lalit-4071902
    Options
     Any update on this?
  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
     we have a partial update to this. I would recommend trying out our Lambda support if this is a big concern for your use case. You can 100% use try/catch and switch/case in a Lambda, which hopefully can tie you over until our next iteration of the function stack is released.
  • Achin Lalit-4071902
    Options
     Yes that worked.  :)
  • Kevin Wasie
    Kevin Wasie Member
    Options
    2nd this. Case/switch would clean up stack considerably.
  • Valentin R
    Options

    Can anyone throw in an example of a switch as a lambda, done in Xano? Would appreciate

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Switch/case is most easily done now as a sequence of if-else conditionals. Since switch is exclusive, you can check for "if x = a then... if x = b then...." as a stack without having to nest them in "else". That's what I usually advise people to do. Using the "return" utility function mixes with this pattern very well too.

    Lambdas are more helpful for complicated situations that might require something like a try-catch, since them failing will not crash the current function stack. Another path on that is to connect to an internal-only API endpoint to handle that logic. That way an error on that other endpoint would generate a 500 that your current function stack could check for in the response, but not be crashed by.

  • Valentin R
    Valentin R Member
    edited November 2022
    Options

    Thanks, @Ray Deck. Just un-nested a few conditionals. Definitely easier to work this way but I understand there is a tiny bit of extra processing on the function this way, compared to a switch. But that's ok for me.

  • Ambroise
    Ambroise Member
    Options

    I only understood today there is no Switch, but even more surprising, the If…Else doesn't handle Else if branch.

    That's quite surprising, and a real struggle to overcome. "Else if" is more important than doing Switch (IMHO), because it can also be used to handle Switch use-cases.