Skip to navigation

Errors in Fern Definition

View as Markdown

Fern Definition isn’t recommended for new customers and Fern isn’t accepting feature requests for this format. It remains supported for existing users.

Errors represent failed (non-200) responses from endpoints.

An error has:

  • An HTTP status code
  • A body type (Optional)
user.yml
errors:
UserNotFoundError:
status-code: 404
type: UserNotFoundErrorBody
types:
UserNotFoundErrorBody:
properties:
requestedUserId: string

Wildcard status codes

status-code also accepts 4XX or 5XX (case-insensitive). 4XX matches any 400–499 response that no other error declares explicitly; 5XX matches any 500–599 response. A concrete status code such as 404 always takes precedence over a wildcard, and fern check treats 4XX and 400 as distinct status codes.

errors.yml
errors:
ClientRequestError:
status-code: 4XX
type: ApiError
ServerError:
status-code: 5XX
type: ApiError

The Go SDK generator decodes wildcard errors into their typed error classes and preserves the actual response status code (for example, 429). Other generators map 4XX to 400 and 5XX to 500.