Skip to content

Function: createApiError()

@kortexya/reasoninglayer


@kortexya/reasoninglayer / createApiError

createApiError(status, body, headers): ApiError

Defined in: src/errors.ts:998

Factory function that creates the appropriate ApiError subclass for a given HTTP status.

number

HTTP status code.

unknown

Parsed response body.

Headers

Response headers.

ApiError

The appropriate error subclass instance.

Status code mapping:

The message is the body’s message string whenever there is one, whether or not the body also carries an error field: the OSFQL, SPARQL and property-graph error bodies carry error_type + message and no error. errorCode is the body’s error string, when present.

Exported from the package root so that a caller can type a failure the SDK did not throw itself, such as the error event of conversation.sendMessageStream.

const error = createApiError(503, { error: 'llm unavailable', message: 'llm unavailable' }, new Headers());
error instanceof ServiceUnavailableError; // true