Skip to main content

Error handling

Unified error shape returned by all SDK form hooks and error handlers. Every caught error — API, validation, network, or runtime — is normalized into SDKError.

SDKError

Unified error shape returned by every form hook and error-handling surface.

Remarks

Every caught error — whether from the Gusto API, client-side Zod validation, a network failure, or an unexpected runtime exception — is normalized into this shape. The SDKErrorCategory category field distinguishes which source produced the error; fieldErrors is populated for structured API responses (typically 422) and is an empty array otherwise.

Observability telemetry uses ObservabilityError, which extends this shape with component context.

Example

import { useEmployeeForm } from '@gusto/embedded-react-sdk'

const { errorHandling } = useEmployeeForm({ employeeId })
const error = errorHandling.error

if (error) {
console.log(error.category) // 'api_error'
console.log(error.httpStatus) // 422
console.log(error.fieldErrors) // [{ field: 'firstName', ... }]
}

Extended by

Properties

PropertyTypeDescription
categorySDKErrorCategoryHigh-level error classification
fieldErrorsSDKFieldError[]Flattened field-level errors from API responses. Empty array for non-field errors.
messagestringHuman-readable error summary
httpStatus?numberHTTP status code (undefined for non-HTTP errors like network or validation)
raw?unknownThe original error object for advanced use cases. May be stripped by sanitization (controlled by sanitization.includeRawError).

SDKErrorCategories

const SDKErrorCategories: object

Constant map of SDKErrorCategory string values keyed by uppercase name.

Remarks

Use this when you need to reference a category value by name (e.g. SDKErrorCategories.API_ERROR). Each entry corresponds to one classification:

ValueWhen it applies
api_errorHTTP error response from the Gusto API (422, 404, 409, 500, etc.)
validation_errorClient-side Zod schema validation before the request was sent
network_errorNetwork connectivity failure (connection refused, timeout, abort)
internal_errorUnexpected runtime error (unhandled exception, initialization failure)

Type Declaration

NameType
API_ERROR"api_error"
INTERNAL_ERROR"internal_error"
NETWORK_ERROR"network_error"
VALIDATION_ERROR"validation_error"

SDKErrorCategory

SDKErrorCategory = "api_error" | "validation_error" | "network_error" | "internal_error"

High-level classification of where an SDKError originated.


SDKFieldError

A flattened, field-level error extracted from an API response.

Remarks

For API errors with structured field errors (e.g. 422 responses), nested errors[] structures are recursively flattened into one entry per leaf field. The field property is the dot-separated camelCase path (e.g. "firstName", "states.CA.filingStatus.value").

Properties

PropertyTypeDescription
categorystringAPI error category (e.g. "invalid_attribute_value", "invalid_operation", "payroll_blocker")
fieldstringDot-separated camelCase field path (e.g. "firstName", "states.CA.filingStatus.value")
messagestringHuman-readable error message from the API
metadata?Record<string, unknown>Additional metadata from the API (e.g. { key: "missing_bank_info" } for payroll blockers)