Can retrieve server exception from a Slate Action widget

Submitting a Slate action client-side I could receive a success or a failure.

In case of failure I’d like to show a message/toast with the text coming from a custom exception thrown server-side (via ontology action written in typescript repo).

I’m able to show a fixed client-side text on failure catching the widget failure callback event but I can’t catch the text exception coming from the server.

Could you please help me on it?

My steps:

  • created ontology object
  • linked an action (typescript server-side repo) to the above object which does something
  • put in Slate a widget to submit my custom action
  • In case of error, created an event to set a variable shown a fixed text error in a label

I’d like to replace “fixed text error” to “error text coming from exception thrown server-side”.

is it possible? how?

Thanks, cinghio

Hello @cinghio

It is possible to intercept an error thrown from an Action, provided that it’s of a class UserFacingError (which can be imported in the typescript repo from "@foundry/functions-api"):

  1. Make your Function annotated by @OntologyEditFunction(), example:
import { UserFacingError, OntologyEditFunction } from "@foundry/functions-api";

export class MyFunctions {
    
    @OntologyEditFunction()
    public SlateTestOntologyThrows(): void {
        throw new UserFacingError("This function has thrown!");
    } 
...
  1. Link that Function to an Action in the Ontology app
  2. Now, in Slate you can pick that Action in the Foundry Action widget w_foundry_action_1 configuration
  3. The Event/Action pair you’d want to set up now is on w_foundry_action_1.failure which will have an argument passed into the function body of the following shape { message: "<message-from-UserFacingError>"}. You can access that value using {{slEventValue.message}}:

When some additional wiring up is done for the toast to open (upon same Event) you can see the message from UserFacingError in the toast! Please lmk whether this is the setup you were looking for.

Hi @drusak,
thank you very much for your answer.

I did exactly what you suggested but I threw a generic exception (Error) instead of an UserFacingError: this was my mistake.
That’s why client-side the global variable {{slEventValue}} was empty.

Fixing the exception type as you wrote me everything works correctly.

Thanks for your time and your solution!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.