Response helpers¶
The SDK exports a set of typed response helpers. Use them instead of returning a plain FunctionResponse object when you want readable, self-documenting status codes.
Success helpers¶
ok(body)¶
Returns { status: 200, body }.
created(body)¶
Returns { status: 201, body }.
accepted(body?)¶
Returns { status: 202, body }. Use for long-running operations where the result is not yet available.
noContent()¶
Returns { status: 204 }. No body.
Error helpers¶
These return a FunctionResponse — they do not throw. Use them when you want to return a structured error response without stopping execution flow with an exception.
For errors that must halt execution (e.g. auth failures, validation errors that prevent the handler from continuing), throw FunctionError instead.
Run-as-job behavior: when the function runs as a UiPath job (no HTTP caller), returning any response with status ≥ 400 reports the job as Faulted, with the message surfaced in Orchestrator's job error info (
{ error }maps to the error title,detailsto its detail). On the HTTP path the response body is returned to the caller verbatim, exactly as written.
badRequest(message?, details?)¶
badRequest(message?: string, details?: unknown): FunctionResponse<{ error: string; details?: unknown }>
Returns { status: 400, body: { error, details? } }.
return badRequest("folderId is required");
return badRequest("Invalid input", { field: "folderId", reason: "must be positive" });
unauthorized(message?)¶
Returns { status: 401, body: { error } }.
forbidden(message?)¶
Returns { status: 403, body: { error } }.
notFound(message?)¶
Returns { status: 404, body: { error } }.
conflict(message?)¶
Returns { status: 409, body: { error } }.
Generic helper¶
response(status, body?, headers?)¶
response<T>(status: number, body?: T, headers?: Record<string, string>): FunctionResponse<T | undefined>
Full control over status, body, and headers.
Response helpers vs FunctionError¶
| Response helpers | FunctionError |
|
|---|---|---|
| Throws | No — returns a value | Yes — throws an exception |
| Execution continues | Yes | No |
| Use for | Conditional branches that return different statuses | Auth failures, validation errors, unexpected conditions |