What is a better way to do this giant stack of if statements?

I am handling sign in and other error responses from firebase auth. for each message i would like to create a friendly human readable message, and take certain actions.

I am capturing the error response from the HTTP request for sign in, and this clump of formula sits in a set page variable formula bar to set my variable to ready friendly. Is there a better way to do this, than this: (I will worry about actions later.)

IF(IS_EQUAL(outputs["signInRequest"].resBodyParsed.error.message, "MISSING_EMAIL"), "Missing Email", IF(IS_EQUAL(outputs["signInRequest"].resBodyParsed.error.message, "INVALID_EMAIL"), "Invalid Email", IF(IS_EQUAL(outputs["signInRequest"].resBodyParsed.error.message, "MISSING_PASSWORD"), "Missing Password", IF(IS_EQUAL(outputs["signInRequest"].resBodyParsed.error.message, "EMAIL_NOT_FOUND"), "Email not found", IF(IS_EQUAL(outputs["signInRequest"].resBodyParsed.error.message, "INVALID_PASSWORD"), "Invalid Password", IF(IS_EQUAL(outputs["signInRequest"].resBodyParsed.error.message, "USER_DISABLED"), "Account Disabled", "Error"))))))

You could use a custom JS flow component and use the javascript switch function!

1 Like

As clunky as it looks, that is about as good as you can achieve with formula scripting.

1 Like

Set up a page variable as a static object, set property names to the various resBodyParsed.error.message(s), and the values are the nicely formatted/human readable versions.

The trick here is to initialize the object with values, and that’s a little hidden (click the gear)…

image

Then use LOOKUP to change the output of the error message into the human readable form.