Unable to catch a fireEvent error

Is it possible that currently an error in a fireEvent function will not raise an error which can be caught via regular try / catch statements?

Below does not seem to work if e.g. the object assigned to the fireEvent function does not match the expected return type.

    try {
        fireEvent("On Success", result_object);
    } catch (e) {
        fireEvent("On Error", e);
    }

What I am trying to achieve is that if the object returned to the fireEvent function does not match the expected object structure, it should fire the error trigger rather than the success trigger.

… or is there maybe a utility function which allows you to check types before handing them over to the final trigger?

To keep Custom Widgets secure, they’re wrapped in an iframe. The checking for the types happens outside the iframe (so that the CW can’t get around it), which is why you aren’t able to catch it.

I’m curious to hear a bit about your use case. The type of the event is static – it’s always the same. Why is the result_object a dynamic type? Since the event type is static, couldn’t you just add some code to check the type?

Hi, i see. The input is static as it is a plain text but that plain text in this case is a complex barcode which wraps several parameters which I need to parse and want to spit out as a structured object so it is easier to work with later on in the app. And this is where the problem arises when the operator e.g. scanned some random barcode which does not fit the specification.

Got it, makes sense. I’ll add a ticket to start throwing those errors within the iframe boundary as well, although it’ll probably further down on the backlog. For now, checking it yourself in code is probably the best path forward.

Understood. Thank you,.