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. For example:
Copied!
1
2
3
4
5
6
7
8
9
10
11
12
13
import { Function, UserFacingError } from "@foundry/functions-api";
import { Employee } from "@foundry/ontology-api";
export class MyFunctions {
@Function()
public async searchExactlyFiveEmployees(employees: Employee[]): Proimse<string> {
if (employees.length != 5) {
throw new UserFacingError(`Pass in exactly 5 employees. Received ${employees.length}.`);
}
// search employees
}
}
Copied!
1
2
3
4
5
6
7
8
9
10
11
import { Osdk } from "@osdk/client";
import { Employee } from "@ontology/sdk";
import { UserFacingError } from "@osdk/functions";
export default async function searchExactlyFiveEmployees(employees: Array<Osdk.Instance<Employee>>): Promise<string> {
if (employees.length != 5) {
throw new UserFacingError(`Pass in exactly 5 employees. Received ${employees.length}.`);
}
// search employees
}
Copied!
1
2
3
4
5
6
7
8
9
10
11
12
from functions.api import function, UserFacingError
from ontology_sdk import FoundryClient
from ontology_sdk.ontology.objects import Aircraft
@function()
def search_exactly_five_employees(
employees: list[Aircraft]
) -> str:
if not len(aircraft) == 5:
raise UserFacingError(f"Pass in exactly 5 employees. Received ${len(aircraft)}.")
# search employees