Throw a user-facing error

When running Functions in other parts of the platform, such as Workshop or Actions, you may want to throw an error with a detailed message. To do so, throw a UserFacingError from the @foundry/functions-api package. For example:

Copied!
1 2 3 4 5 6 7 8 9 10 11 import { Edits, OntologyEditFunction, UserFacingError } from "@foundry/functions-api"; import { Employee } from "@foundry/ontology-api"; @Edits(Employee) @OntologyEditFunction() public editExactlyFiveEmployees(employees: Employee[]): void { if (employees.length != 5) { throw new UserFacingError(`Pass in exactly 5 employees. Received ${employees.length}.`); } ... }

When running this as a Function-backed Action in a Workshop application with an incorrect number of employees, users will see the following error:

user-facing-error

By adding a detailed user facing error message, you can help other users of your Function quickly identify and fix the issue.