I’m interested in propagating failure messages to the frontend to alert the end user if an action has failed, as well as provide something that is actionable to the end user. Is that possible and if so, how do I implement it?
If your Action is Function-backed, both Python and TypeScript Functions allow you to import an error type whose message is intended to be seen by end-users.
Python:
from foundry_sdk_runtime import OntologyEdit
from functions.api import UserFacingError
from ontology_sdk.ontology.objects import Aircraft
@function
def throw_user_facing_error(aircraft: Aircraft) -> list[OntologyEdit]:
if aircraft.capacity < 100:
raise UserFacingError("This aircraft does not meet the required capacity.")
# ...
TypeScript:
import { OntologyEditFunction, UserFacingError } from "@foundry/functions-api";
import { Aircraft } from "@foundry/ontology-api";
export class MyFunctions {
@OntologyEditFunction()
public throwUserFacingError(aircraft: Aircraft): void {
if (aircraft.capacity < 100) {
throw new UserFacingError("This aircraft does not meet the required capacity.");
}
// ...
}
}
If you wire this Function into an Action and use it in a Workshop app, users will see these user-facing errors in the form of a red toast.
1 Like
Thank you! That’s very clear.